BExIS.Dlm.Services.Party.PartyManager.Create C# (CSharp) Метод

Create() публичный Метод

public Create ( PartyType partyType, string name, string alias, string description, System.DateTime startDate, System.DateTime endDate, PartyStatusType statusType ) : Party
partyType BExIS.Dlm.Entities.Party.PartyType
name string
alias string
description string
startDate System.DateTime
endDate System.DateTime
statusType BExIS.Dlm.Entities.Party.PartyStatusType
Результат BExIS.Dlm.Entities.Party.Party
        public PartyX Create(PartyType partyType, string name, string alias, string description, DateTime? startDate, DateTime? endDate, PartyStatusType statusType)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(name));
            Contract.Requires(partyType != null);
            Contract.Requires(statusType != null);
            Contract.Requires(partyType.StatusTypes.Contains(statusType));
            Contract.Ensures(Contract.Result<PartyX>() != null && Contract.Result<PartyX>().Id >= 0);
            if (startDate == null)
                startDate = DateTime.MinValue;
            if (endDate == null || endDate==DateTime.MinValue)
                endDate = DateTime.MaxValue;
            //Create a create status
            PartyStatus initialStatus = new PartyStatus();
            initialStatus.Timestamp = DateTime.UtcNow;
            initialStatus.Description = "Created";
            initialStatus.StatusType = statusType;

            PartyX entity = new PartyX()
            {
                PartyType = partyType,
                Name = name,
                Alias = alias,
                Description = description,
                StartDate = startDate.Value,
                EndDate = endDate.Value,
                CurrentStatus = initialStatus
            };
            initialStatus.Party = entity;
            entity.History = new List<PartyStatus>();
            entity.History.Add(initialStatus);
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<PartyX> repo = uow.GetRepository<PartyX>();
                repo.Put(entity); // must store the status objects too
                uow.Commit();
            }
            return (entity);
        }

Usage Example

Пример #1
0
        public ActionResult Create(PartyModel partyModel, Dictionary<string, string> partyCustomAttributeValues)
        {
            PartyTypeManager partyTypeManager = new PartyTypeManager();
            PartyManager partyManager = new PartyManager();
            validateAttribute(partyModel);
            if (partyModel.Errors.Count > 0)
                return View(partyModel);
            //
            var partyType = partyTypeManager.Repo.Get(partyModel.Party.PartyType.Id);
            var partyStatusType = partyTypeManager.GetStatusType(partyType, "Create");

            //Create party
            var party = partyManager.Create(partyType, partyModel.Party.Name, "", "", partyModel.Party.StartDate, partyModel.Party.EndDate, partyStatusType);
            //Add customAttriuteValue to party
            partyManager.AddPartyCustomAttriuteValue(party, ConvertDictionaryToPartyCustomeAttrValuesDictionary(partyCustomAttributeValues));
            return RedirectToAction("Index");
        }