コード例 #1
0
        public ActionResult Create(Owner model)
        {
            bool check = false;

            if (model.FirstName == null)
            {
                check = true;
            }
            if (model.MiddleName == null)
            {
                check = true;
            }
            if (model.LastName == null)
            {
                check = true;
            }
            if (model.DOB == null)
            {
                check = true;
            }
            if (model.AddressNumber == null)
            {
                check = true;
            }
            if (model.AddressName == null)
            {
                check = true;
            }
            if (model.PostcodeID == null)
            {
                check = true;
            }
            if (check)
            {
                return(View(model));
            }


            char[]             delimiter         = { ',' };
            string[]           temp              = model.PostcodeID.Split(delimiter, StringSplitOptions.RemoveEmptyEntries);
            EncryptionServices encryptionService = new EncryptionServices();
            SailiRepository    repository        = new SailiRepository();
            Vector <Postcode>  Locality          = new Vector <Postcode>();

            model.UserID = User.Identity.GetUserId();
            model        = encryptionService.EncryptOwner(model);

            temp = repository.RemoveEmptyEntries(temp);
            string post = temp[0];

            Locality = repository.GetLocality(post);

            try
            {
                foreach (var item in Locality)
                {
                    if (item == null)
                    {
                        break;
                    }

                    if (item.postcode.Equals(temp[0].ToString()) &&
                        item.Locality.Equals(temp[1].ToString()))
                    {
                        model.PostcodeID = item.PostcodeID.ToString();
                    }
                }
                DefaultConnection.Owners.Add(new Owner()
                {
                    OwnerID       = model.OwnerID,
                    UserID        = model.UserID,
                    FirstName     = model.FirstName,
                    MiddleName    = model.MiddleName,
                    LastName      = model.LastName,
                    DOB           = model.DOB,
                    AddressNumber = model.AddressNumber,
                    AddressName   = model.AddressName,
                    PostcodeID    = model.PostcodeID
                });
                DefaultConnection.SaveChanges();


                return(RedirectToAction("CheckStatusTrader", "TraderAccount", new
                {
                    OwnerID = model.OwnerID.ToString()
                }));
            }
            catch
            {
                return(View(model));
            }
        }