public ActionResult Edit([Bind(Include = "Id,Name,PurchasePrice,SalePrice,Stock,Saleable,SupplierId,PerPack,ImgPath")] Product product)
        {
            //Product prd = db.Products.Where(x => x.Id == product.Id).FirstOrDefault();
            //product.SuppId = prd.SuppId;
            if (product.Stock == null)
            {
                product.Stock = 0;
            }

            if (product.PerPack == null || product.PerPack == 0)
            {
                product.PerPack = 1;
            }

            product.Stock = product.Stock * product.PerPack;


            if (ModelState.IsValid)
            {
                db.Entry(product).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(product));
        }
        public ActionResult Edit([Bind(Include = "Email,Password,bizId,DepartmentId,ImgPath")] Employee userChanges, FormCollection fc)
        {
            string oldPass = fc["OldPassword"];
            string pass1   = fc["Password1"];
            string pass2   = fc["Password2"];

            Employee CurrentUser = (Employee)Session["CurrentUser"];

            if (CurrentUser.Email == userChanges.Email && CurrentUser.Password == Encryption.Encrypt(oldPass) && pass1 == pass2)
            {
                userChanges.Id = CurrentUser.Id;
                //userChanges.Login = userChanges.Login;
                userChanges.Password         = Encryption.Encrypt(pass2);
                userChanges.FirstName        = CurrentUser.FirstName;
                userChanges.LastName         = CurrentUser.LastName;
                userChanges.RegistrationDate = CurrentUser.RegistrationDate;
                userChanges.UpdateDate       = DateTime.Now;
                userChanges.Login            = CurrentUser.Email.Split('@').FirstOrDefault();

                if (ModelState.IsValid)
                {
                    db.Entry(userChanges).State = EntityState.Modified;
                    db.SaveChanges();
                    Session.Add("CurrentUser", userChanges);
                    //ViewBag.IsReturn = "false";
                    //return RedirectToAction("Create","SOSR", "false");
                    return(RedirectToAction("Create", "SOSR", new { IsReturn = "false" }));//change it from 'if condtion' to here
                }
            }

            ViewBag.Error = "Password does not match";
            return(View(userChanges));
        }
Exemple #3
0
        public ActionResult Edit([Bind(Include = "Login,Password")] Employee userChanges, FormCollection fc)
        {
            string oldPass = fc["OldPassword"];
            string pass1   = fc["Password1"];
            string pass2   = fc["Password2"];

            Employee CurrentUser = (Employee)Session["CurrentUser"];

            if (CurrentUser.Login == userChanges.Login && CurrentUser.Password == Encryption.Encrypt(oldPass) && pass1 == pass2)
            {
                userChanges.Id = CurrentUser.Id;
                //userChanges.Login = userChanges.Login;
                userChanges.Password = Encryption.Encrypt(pass2);

                if (ModelState.IsValid)
                {
                    db.Entry(userChanges).State = EntityState.Modified;
                    db.SaveChanges();
                    Session.Add("CurrentUser", userChanges);

                    return(RedirectToAction("Create", "SOSR"));
                }
            }

            ViewBag.Error = "Password does not match";
            return(View(userChanges));
        }
        public async Task <IActionResult> PutProduct(int id, Product product)
        {
            if (id != product.ProductID)
            {
                return(BadRequest());
            }

            _context.Entry(product).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public ActionResult Create([Bind(Include = "SOId,PaymentMethod,PaymentAmount,Id,ReceivedDate,Remarks")] Payment payment)
        {
            string codedId = payment.SOId;

            string SOId = Decode(payment.SOId);
            SO     sO   = db.SOes.Where(x => x.Id == SOId).FirstOrDefault();
            //Customer thisCust= sO.Customer;
            int maxId = db.Payments.DefaultIfEmpty().Max(p => p == null ? 0 : p.Id);

            maxId     += 1;
            payment.Id = maxId;
            if (ModelState.IsValid)
            {
                payment.ReceivedDate = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("Pakistan Standard Time"));
                payment.SOId         = SOId;
                db.Payments.Add(payment);
                ////////////////add to SO table
                //SO newSO = new SO();
                //newSO.Id = System.Guid.NewGuid().ToString().ToUpper();
                //newSO.SOSerial = sO.SOSerial;
                //newSO.BillAmount = 0;
                sO.BillPaid         += payment.PaymentAmount;
                sO.PrevBalance       = sO.Customer.Balance;   //customer last balnce will go to prev balance
                sO.Customer.Balance -= payment.PaymentAmount; //minus this amout from total balance also
                sO.Balance           = sO.Customer.Balance;
                sO.Date              = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("Pakistan Standard Time"));

                //db.SOes.Add(sO);
                db.Entry(sO).State = EntityState.Modified;
                /////////////
                db.SaveChanges();

                string orderId = string.Join("-", ASCIIEncoding.ASCII.GetBytes(Encryption.Encrypt(payment.SOId)));
                //public ActionResult Create(string custName, string orderNo, string id)
                return(RedirectToAction("Create", new { custName = sO.Customer.Name, orderNo = sO.SOSerial, id = orderId }));
            }
            return(RedirectToAction("Create", new { custName = sO.Customer.Name, orderNo = sO.SOSerial, id = codedId }));

            //SO sO1 = db.SOes.Where(x => x.Id == SOId).FirstOrDefault();
            //ViewBag.custName = sO1.Customer.Name;
            //ViewBag.orderNo = sO1.SOSerial;
            //ViewBag.Payments = db.Payments.Where(p => p.SOId == SOId);
            //ViewBag.id = string.Join("-", ASCIIEncoding.ASCII.GetBytes(Encryption.Encrypt(SOId)));//Decode( id);
            ////ViewBag.SOId = new SelectList(db.SOes.OrderByDescending(i => i.Date), "Id", "Remarks");
            //ViewBag.TodayDate = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("Pakistan Standard Time")).ToString("dd-MMM-yyy");
            //return View(payment);
        }
 public ActionResult Edit([Bind(Include = "ID,Name,EnrollmentDate")] Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(employee);
 }
Exemple #7
0
 public ActionResult Edit([Bind(Include = "StoreId,Name,Adress")] Store store)
 {
     if (ModelState.IsValid)
     {
         db.Entry(store).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(store));
 }
 public ActionResult Edit([Bind(Include = "Id,Name,Remarks,CreateDate,UpdateDate")] Location location)
 {
     if (ModelState.IsValid)
     {
         db.Entry(location).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(location));
 }
 public ActionResult Edit([Bind(Include = "Id,Name,Price")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(product));
 }
 public ActionResult Edit([Bind(Include = "JobID,Title")] Job job)
 {
     if (ModelState.IsValid)
     {
         db.Entry(job).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(job));
 }
 public ActionResult Edit([Bind(Include = "CategoryID,CategoryName,Description")] Category category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }
 public ActionResult Edit([Bind(Include = "ItemID,ItemName,ItemPrice,Image")] Item item)
 {
     if (ModelState.IsValid)
     {
         db.Entry(item).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(item));
 }
 public ActionResult Edit([Bind(Include = "Id,Name,Address,Balance")] Supplier supplier)
 {
     if (ModelState.IsValid)
     {
         db.Entry(supplier).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(supplier));
 }
Exemple #14
0
 public ActionResult Edit([Bind(Include = "bizId,Id,Name,Remarks,CreateDate,UpdateDate")] Department department)
 {
     if (ModelState.IsValid)
     {
         db.Entry(department).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(department));
 }
 public ActionResult Edit([Bind(Include = "ItemID,ItemName,ItemDescription,SellerName")] Item item)
 {
     if (ModelState.IsValid)
     {
         db.Entry(item).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.SellerName = new SelectList(db.Sellers, "SellerName", "SellerName", item.SellerName);
     return(View(item));
 }
Exemple #16
0
 public void RefuseUpdateStatusUser(Guid id)
 {
     using (var ctx = new BusinessContext())
     {
         var toRefuse = GetUpdateStatusById(id);
         toRefuse.State            = 3;
         toRefuse.AnswerTimeStamp  = DateTime.Now;
         ctx.Entry(toRefuse).State = System.Data.Entity.EntityState.Modified;
         ctx.SaveChanges();
     }
 }
Exemple #17
0
 public ActionResult Edit([Bind(Include = "ID,FirstName,LastName,Username,CompanyID")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CompanyID = new SelectList(db.Companies, "ID", "Name", user.CompanyID);
     return(View(user));
 }
Exemple #18
0
        public async Task <ActionResult> Edit([Bind(Include = "AreaID,Name")] Area area)
        {
            if (ModelState.IsValid)
            {
                db.Entry(area).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(area));
        }
Exemple #19
0
 public ActionResult Edit([Bind(Include = "Id,FirstName,LastName,Gender,Login,Password,Email,EmployeeTypeId,RightId,RankId,DepartmentId,Designation,Probation,RegistrationDate,Casual,Earned,IsActive,CreateDate,UpdateDate")] Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DepartmentId = new SelectList(db.Departments, "Id", "Name", employee.DepartmentId);
     return(View(employee));
 }
 public ActionResult Edit([Bind(Include = "BidID,ItemID,BuyerName,Price,Timestamp")] Bid bid)
 {
     if (ModelState.IsValid)
     {
         db.Entry(bid).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.BuyerName = new SelectList(db.Buyers, "BuyerName", "BuyerName", bid.BuyerName);
     ViewBag.ItemID    = new SelectList(db.Items, "ItemID", "ItemName", bid.ItemID);
     return(View(bid));
 }
Exemple #21
0
        public async Task <ActionResult> Edit([Bind(Include = "ContactID,AreaID,FirstName,LastName,BirthDate")] Contact contact)
        {
            if (ModelState.IsValid)
            {
                db.Entry(contact).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.AreaID = new SelectList(db.Areas, "AreaID", "Name", contact.AreaID);
            return(View(contact));
        }
Exemple #22
0
 public ActionResult Edit([Bind(Include = "EnrollmentID,EmployeeID,JobID")] Enrollment enrollment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(enrollment).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.EmployeeID = new SelectList(db.Employees, "ID", "Name", enrollment.EmployeeID);
     ViewBag.JobID      = new SelectList(db.Jobs, "JobID", "Title", enrollment.JobID);
     return(View(enrollment));
 }
Exemple #23
0
        public async Task <ActionResult> Edit([Bind(Include = "AddressID,ContactID,Description")] Address address)
        {
            if (ModelState.IsValid)
            {
                db.Entry(address).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.ContactID = new SelectList(db.Contacts, "ContactID", "FirstName", address.ContactID);
            return(View(address));
        }
Exemple #24
0
        // GET: ProductGuides
        public async Task <IActionResult> Index(int?id, int?productID)
        {
            var viewModel = new ProductGuideIndexData();

            viewModel.ProductGuides = await _context.ProductGuides
                                      .Include(i => i.CountryAssignment)
                                      .Include(i => i.ProductAssignments)
                                      .ThenInclude(i => i.Product)
                                      .ThenInclude(i => i.Subscriptions)
                                      .ThenInclude(i => i.Customer)
                                      .Include(i => i.ProductAssignments)
                                      .ThenInclude(i => i.Product)
                                      .ThenInclude(i => i.Market)
                                      .AsNoTracking()
                                      .OrderBy(i => i.LastName)
                                      .ToListAsync();

            if (id != null)
            {
                ViewData["ProductGuideID"] = id.Value;
                ProductGuide productGuide = viewModel.ProductGuides.Where(
                    i => i.ID == id.Value).Single();
                viewModel.Products = productGuide.ProductAssignments.Select(s => s.Product);
            }

            if (productID != null)
            {
                ViewData["ProductID"] = productID.Value;
                var selectedProduct = viewModel.Products.Where(x => x.ProductID == productID).Single();
                await _context.Entry(selectedProduct).Collection(x => x.Subscriptions).LoadAsync();

                foreach (Subscription subscription in selectedProduct.Subscriptions)
                {
                    await _context.Entry(subscription).Reference(x => x.Customer).LoadAsync();
                }
                viewModel.Subscriptions = selectedProduct.Subscriptions;
            }

            return(View(viewModel));
        }
 private void ReflectionToSetUpdatedValues(Employee original, Employee updatedUser)
 {
     foreach (PropertyInfo propertyInfo in original.GetType().GetProperties())
     {
         if (propertyInfo.GetValue(updatedUser, null) == null)
         {
             propertyInfo.SetValue(updatedUser, propertyInfo.GetValue(original, null), null);
         }
     }
     BusinessContext.Attach(updatedUser);
     BusinessContext.Entry(updatedUser).State = EntityState.Modified;
     BusinessContext.SaveChanges();
 }
 public ActionResult Edit([Bind(Include = "Id,ProductId,CustomerId,StoreId,DateSold")] ProductSold productSold)
 {
     if (ModelState.IsValid)
     {
         db.Entry(productSold).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CustomerId = new SelectList(db.Customers, "Id", "Name", productSold.CustomerId);
     ViewBag.ProductId  = new SelectList(db.Products, "Id", "Name", productSold.ProductId);
     ViewBag.StoreId    = new SelectList(db.Stores, "Id", "Name", productSold.StoreId);
     return(View(productSold));
 }
Exemple #27
0
        public void AcceptUpdateStatusUser(Guid id)
        {
            using (var ctx = new BusinessContext())
            {
                var toAccept = GetUpdateStatusById(id);
                toAccept.State            = 2;
                toAccept.AnswerTimeStamp  = DateTime.Now;
                ctx.Entry(toAccept).State = System.Data.Entity.EntityState.Modified;

                EditUserStatus(toAccept.UserId, toAccept.NewStatus, toAccept.Path);

                ctx.SaveChanges();
            }
        }
        public async Task <ActionResult> Update(int id, Employee emp)
        {
            try
            {
                emp.Id = id;

                BusinessContext.Employees.Attach(emp); // one query on DB (find and update)
                var entry = BusinessContext.Entry(emp);
                entry.State = EntityState.Modified;    // all properties will be updated according to model's properties of the view. view must have all properties
                                                       // entry.Property(e=>e.BirthDate).IsModified = false; // in case u dont want to modify the field in Db
                                                       // or use update to replace these 3 lines if all properties are modified
                await BusinessContext.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            catch (DbUpdateException e)
            {
                ModelState.AddModelError(string.Empty, "cannot update entity " + e.Message);
            }

            return(View(emp));
        }
Exemple #29
0
        public bool EditPassWord(Guid userId, string password)
        {
            using (var ctx = new BusinessContext())
            {
                var query = from u in ctx.Users
                            where u.Id == userId
                            select u;
                User usr = query.FirstOrDefault();

                if (usr != null)
                {
                    return(false);
                }
                else
                {
                    usr.Password         = SHA.GenerateSHA256String(password);
                    ctx.Entry(usr).State = System.Data.Entity.EntityState.Modified;
                    ctx.SaveChanges();

                    return(true);
                }
            }
        }
Exemple #30
0
        public bool EditStatus(Guid userId, string status, string filename)
        {
            using (var ctx = new BusinessContext())
            {
                var query = from u in ctx.Users
                            where u.Id.Equals(userId)
                            select u;
                User usr = query.FirstOrDefault();

                if (usr == null)
                {
                    return(false);
                }
                else
                {
                    usr.Status           = status;
                    ctx.Entry(usr).State = System.Data.Entity.EntityState.Modified;
                    ctx.SaveChanges();

                    return(true);
                }
            }
        }