Ejemplo n.º 1
0
        public ActionResult CreateStore(StoreViewModel store, IEnumerable <HttpPostedFileBase> files)
        {
            // to create dropdownlist

            StoreViewModel dropdown = DropdownforCompany();

            try
            {
                if (Session[KeyList.SessionKeys.UserID] != null)
                {
                    var userId = Session[KeyList.SessionKeys.UserID].ToString();
                    if (ModelState.IsValid)
                    {
                        if (Checknumber(store.Contact) == false)
                        {
                            ViewBag.message = "Please Add Number without +64 or 0";
                            return(View(dropdown));
                        }
                        var addressss = addressService.Get(a => a.City == store.City && a.Street == store.Street && a.Country == store.Country).SingleOrDefault();
                        if (addressss == null)
                        {
                            bool Image = files.IsValidImageList(false);
                            if (Image == true)
                            {
                                foreach (var item in files)
                                {
                                    var path = item.SaveImageFile();

                                    Store _store = new Store
                                    {
                                        StoreName           = store.StoreName,
                                        UserId              = Convert.ToInt32(userId),
                                        Contact             = "+64" + store.Contact,
                                        IdentificationImage = path,
                                        CompanyId           = store.CompanyId,
                                        IsValid             = false,
                                        IsDeleted           = false,
                                    };

                                    int     id      = storeService.CreateStore(_store);
                                    Address address = new Address
                                    {
                                        Street  = store.Street,
                                        City    = store.City,
                                        Country = store.Country,
                                        StoreId = id,
                                    };
                                    addressService.CreateAddress(address);
                                }
                            }
                            else
                            {
                                ViewBag.message = "Image is required and should only have .pdf,.jpeg,.jpg,.gif";
                                return(View(dropdown));
                            }
                        }
                        Logs GenerateLog = new Logs();
                        GenerateLog.CreateLog(Convert.ToInt32(userId), KeyList.LogMessages.CreateStore);
                        return(RedirectToAction("Store"));
                    }
                }

                return(View(dropdown));
            }
            catch (Exception e)
            {
                return(View(dropdown));
            }
        }
Ejemplo n.º 2
0
 public ActionResult <TAddress> Post(TAddress address)
 {
     _address.CreateAddress(address);
     return(Ok());
 }