Пример #1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    // Store Store, Location and capacity
                    Store_Location storeLocationItem = new Store_Location();
                    storeLocationItem.Store_Id         = model.StoreId;
                    storeLocationItem.Location_Id      = model.LocationId;
                    storeLocationItem.Capacity_Id      = model.CapacityId;
                    storeLocationItem.UserName         = model.Email;
                    storeLocationItem.Current_Capacity = 0;

                    using (var shopSafeEntity = new Entities())
                    {
                        var resultItem = shopSafeEntity.Store_Location.SingleOrDefault(s => s.Store_Id == storeLocationItem.Store_Id && s.Location_Id == storeLocationItem.Location_Id);
                        if (resultItem != null)
                        {
                            resultItem.Capacity_Id = storeLocationItem.Capacity_Id;
                            resultItem.UserName    = storeLocationItem.UserName;
                        }
                        else
                        {
                            shopSafeEntity.Store_Location.Add(storeLocationItem);
                        }
                        shopSafeEntity.SaveChanges();
                    }

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public static void Save(Store_LocationDO model, int userID)
        {
            Repository<Store_Location> rep = new Repository<Store_Location>(CheckoutDataContextProvider.Instance);
            Store_Location dbObject;
         
            if (model.ID == 0)
            {
                dbObject = new Store_Location();
                Mapper.Map<Store_LocationDO, Store_Location>(model, dbObject);
                rep.InsertOnSubmit(dbObject);
            }
            else
            {
                dbObject = rep.GetAll().Where(x => x.ID == model.ID).SingleOrDefault();
                Mapper.Map<Store_LocationDO, Store_Location>(model, dbObject);
            }

            rep.DCP.CommitChanges(userID);
            
            Mapper.Map<Store_Location, Store_LocationDO>(dbObject, model);
                        
        }