예제 #1
0
        public ActionResult Create(User user)
        {
            var IsUNExist = db.User.Any(m => m.Username == user.Username);
            var IsEMExist = db.User.Any(m => m.Email == user.Email);

            if (ModelState.IsValid && !IsUNExist && !IsEMExist)
            {
                db.User.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            if (IsUNExist)
            {
                ModelState.AddModelError("", "Username is already exist.");
            }
            else if (IsEMExist)
            {
                ModelState.AddModelError("", "Email is already exist.");
            }
            else
            {
                ModelState.AddModelError("", "Fill the blanks correctly.");
            }
            return(View(user));
        }
예제 #2
0
        public void AddToCart(Item item)
        {
            // Get the matching cart and item instances
            var cartItem = storeDB.Cart.SingleOrDefault(
                c => c.CartId == ShoppingCartId &&
                c.ItemId == item.Id);

            if (cartItem == null)
            {
                using (var db = new GroceryDBEntities())
                {
                    // Create a new cart item if no cart item exists
                    cartItem = new Cart
                    {
                        ItemId      = item.Id,
                        CartId      = ShoppingCartId,
                        Count       = 1,
                        DateCreated = DateTime.Now
                    };
                    storeDB.Cart.Add(cartItem);
                }
            }
            else
            {
                // If the item does exist in the cart,
                // then add one to the quantity
                cartItem.Count++;
            }
            // Save changes
            storeDB.SaveChanges();
        }
예제 #3
0
        public ActionResult Create([Bind(Include = "Id,Name,IsActive")] CountryTbl countryTbl)
        {
            if (ModelState.IsValid)
            {
                db.CountryTbls.Add(countryTbl);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(countryTbl));
        }
예제 #4
0
        public ActionResult Create([Bind(Include = "Id,Name,StateId,IsActive")] CityTbl cityTbl)
        {
            if (ModelState.IsValid)
            {
                db.CityTbls.Add(cityTbl);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.StateId = new SelectList(db.StateTbls, "Id", "Name", cityTbl.StateId);
            return(View(cityTbl));
        }
예제 #5
0
        public HttpResponseMessage Registration(UserModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState));
            }
            else
            {
                var encryptedPassword = EncryptDecryptPassword.EncryptPlainTextToCipherText(model.Password);

                db.UserTbls.Add(new UserTbl()
                {
                    CityId         = model.CityId,
                    FirstName      = model.FirstName,
                    LastName       = model.LastName,
                    Email          = model.Email,
                    MobileNumber   = model.MobileNumber,
                    FlatNumber     = model.FlatNumber,
                    CountryId      = model.CountryId,
                    StateId        = model.StateId,
                    SocityName     = model.SocityName,
                    DateModified   = DateTime.Now,
                    DateAdded      = DateTime.Now,
                    WhatsAppNumber = model.WhatsAppNumber,
                    WingName       = model.WingName,
                    Landmark       = model.Landmark,
                    Password       = encryptedPassword,
                    UserName       = model.UserName,
                    Token          = model.Token
                });
                db.SaveChanges();
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
        }
예제 #6
0
 public HttpResponseMessage Login(UserTbl model)
 {
     if (ModelState.IsValid)
     {
         var encryptedPasswordString = EncryptDecryptPassword.EncryptPlainTextToCipherText(model.Password);
         var user = db.UserTbls.FirstOrDefault(item => item.UserName == model.UserName && item.Password == encryptedPasswordString);
         if (user != null)
         {
             user.Token = Guid.NewGuid();
             db.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.OK, new
             {
                 Token = user.Token,
                 Name = string.Concat(user.FirstName, " ", user.LastName)
             }));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid Username and password"));
         }
     }
     else
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState));
     }
 }
예제 #7
0
        public ActionResult AddressAndPayment(FormCollection values)
        {
            var order = new Order();

            TryUpdateModel(order);

            try
            {
                var cart = ShoppingCart.GetCart(this.HttpContext);
                order.Username  = User.Identity.Name;
                order.OrderDate = DateTime.Now;
                order.Total     = cart.GetTotal();

                //Save Order
                storeDB.Order.Add(order);
                storeDB.SaveChanges();
                //Process the order

                cart.CreateOrder(order);

                return(RedirectToAction("Complete",
                                        new { id = order.OrderId }));
            }
            catch
            {
                //Invalid - redisplay with errors
                return(View(order));
            }
        }
예제 #8
0
        public ActionResult Save(Item item, HttpPostedFileBase imageUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View("ProductForm", item));
            }

            if (item.Id == 0)
            {
                if (imageUrl != null)
                {
                    string ImageName    = System.IO.Path.GetFileName(imageUrl.FileName);
                    string physicalPath = Server.MapPath("~/UploadedImages/" + ImageName);

                    // save image in folder
                    imageUrl.SaveAs(physicalPath);

                    //save new record in database
                    item.ImageUrl = ImageName;
                    db.Item.Add(item);
                }
            }
            else
            {
                var updateItem = db.Item.Find(item.Id);
                if (updateItem == null)
                {
                    return(HttpNotFound());
                }
                if (imageUrl != null)
                {
                    string ImageName    = System.IO.Path.GetFileName(imageUrl.FileName);
                    string physicalPath = Server.MapPath("~/UploadedImages/" + ImageName);

                    // save image in folder
                    imageUrl.SaveAs(physicalPath);

                    //save new record in database
                    item.ImageUrl = ImageName;
                    db.Entry(updateItem).CurrentValues.SetValues(item);
                }
            }
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
예제 #9
0
        public ActionResult Register(User account)
        {
            if (ModelState.IsValid)
            {
                var usr = db.User.Where(m => m.Username == account.Username || m.Email == account.Email).FirstOrDefault();
                if (usr != null)
                {
                    ModelState.AddModelError("", "Username or Email is already exist.");
                    return(View());
                }

                db.User.Add(account);
                db.SaveChanges();
                TempData["succesRegistered"] = account.Username + " succesfully registered.";
                return(RedirectToAction("Login"));
            }
            return(View());
        }