Example #1
0
        public ActionResult Edit(EmployeeRegisterModel empreg)
        {
            if (ModelState.IsValid)
            {
                Employee emp = new Employee();
                emp.Id              = empreg.Id;
                emp.Name            = empreg.Name;
                emp.TeamId          = empreg.TeamId;
                db.Entry(emp).State = EntityState.Modified;
                db.SaveChanges();

                ApplicationUser userCheck = db.Users.Where(u => u.EmployeeId == emp.Id).FirstOrDefault();
                if (userCheck == null)
                {
                    if (!string.IsNullOrEmpty(empreg.Username) && !string.IsNullOrEmpty(empreg.Password))
                    {
                        if (!db.Users.Any(u => u.UserName == empreg.Username))
                        {
                            var hasher = new PasswordHasher();

                            var user = new ApplicationUser
                            {
                                EmployeeId     = emp.Id,
                                UserName       = empreg.Username,
                                PasswordHash   = hasher.HashPassword(empreg.Password),
                                Email          = "",
                                EmailConfirmed = true,
                                SecurityStamp  = Guid.NewGuid().ToString()
                            };

                            db.Users.Add(user);
                            db.SaveChanges();
                        }
                        else
                        {
                            ModelState.AddModelError("", "Tên đăng nhập đã có người sử dụng !");
                            ViewBag.TeamId = new SelectList(db.Teams, "Id", "Name", empreg.TeamId);
                            return(View(empreg));
                        }
                    }
                }
                else
                {
                    userCheck.UserName        = empreg.Username;
                    db.Entry(userCheck).State = EntityState.Modified;
                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            ViewBag.TeamId = new SelectList(db.Teams, "Id", "Name", empreg.TeamId);
            //ViewBag.PossibleRoles = db.Roles.OrderByDescending(r => r.Name).ToList();
            return(View(empreg));
        }
 public ActionResult _CreateOrEdit(QCTeamModel qcTeamModel)
 {
     if (ModelState.IsValid)
     {
         if (qcTeamModel.QCId == 0)
         {
             return(Json(new { success = false, id = qcTeamModel.TeamId, error = "Chưa chọn QC" }));
         }
         if (qcTeamModel.ApplyAll)
         {
             var factoryId = db.Teams.Find(qcTeamModel.TeamId).FactoryId;
             var teams     = db.Teams.Where(team => team.FactoryId == factoryId).ToList();
             foreach (var team in teams)
             {
                 var qcTeam = new QCTeam
                 {
                     QCId   = qcTeamModel.QCId,
                     TeamId = team.Id,
                     From   = qcTeamModel.From,
                     To     = qcTeamModel.To
                 };
                 if (!db.QCTeams.Any(qct => qct.TeamId == team.Id && qct.QCId == qcTeamModel.QCId))
                 {
                     db.QCTeams.Add(qcTeam);
                 }
                 else
                 {
                     db.Entry(qcTeam).State = EntityState.Modified;
                 }
             }
         }
         else
         {
             var qcTeam = new QCTeam
             {
                 QCId   = qcTeamModel.QCId,
                 TeamId = qcTeamModel.TeamId,
                 From   = qcTeamModel.From,
                 To     = qcTeamModel.To
             };
             if (!db.QCTeams.Any(qct => qct.TeamId == qcTeamModel.TeamId && qct.QCId == qcTeamModel.QCId))
             {
                 db.QCTeams.Add(qcTeam);
             }
             else
             {
                 db.Entry(qcTeam).State = EntityState.Modified;
             }
         }
         db.SaveChanges();
         return(Json(new { success = true, id = qcTeamModel.TeamId, applyAll = qcTeamModel.ApplyAll }));
     }
     return(Json(new { success = false }));
 }
 public ActionResult _Edit(QC qc)
 {
     if (ModelState.IsValid)
     {
         db.Entry(qc).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(_Details(qc.Id));
     }
     else
     {
         return(PartialView(qc));
     }
 }
        public ActionResult Edit(HttpPostedFileBase profileFile, [Bind(Include = "Id,Name,ShortDescription,FullDescription")] Factory factory)
        {
            if (profileFile != null && profileFile.ContentLength > 0)
            {
                string fileName = Convert.ToInt32((DateTime.Now - new DateTime(2010, 01, 01)).TotalSeconds) + "_" + profileFile.FileName;
                string folder   = "uploads/factorypicture";
                string filePath = System.IO.Path.Combine(Server.MapPath(@"~/" + folder), fileName);
                profileFile.SaveAs(filePath);

                factory.Picture = "/" + folder + "/" + fileName;
            }
            else if (String.IsNullOrEmpty(factory.Picture))
            {
                factory.Picture = "/Content/assets/xn1.jpg";
            }

            ModelState.Clear();
            TryValidateModel(factory);
            if (ModelState.IsValid)
            {
                db.Entry(factory).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(factory));
        }
Example #5
0
 public ActionResult Edit([Bind(Include = "Id,StartCountTime,EndCountTime,DayOfWeek,SessionId, Minute")] GoalDetailTemplate goalDetailTemplate)
 {
     if (ModelState.IsValid)
     {
         db.Entry(goalDetailTemplate).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(goalDetailTemplate));
 }
Example #6
0
 public ActionResult Edit([Bind(Include = "Id,Name")] ProductType productType)
 {
     if (ModelState.IsValid)
     {
         db.Entry(productType).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(productType));
 }
 public ActionResult Edit([Bind(Include = "Id,GoalDate,StartHour,EndHour,TeamId,ProductId")] Goal goal)
 {
     if (ModelState.IsValid)
     {
         db.Entry(goal).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(goal));
 }
Example #8
0
 public ActionResult Edit([Bind(Include = "Id,Name, Order, ColorCode, ErrorCode")] Reason item)
 {
     if (ModelState.IsValid)
     {
         db.Entry(item).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(item));
 }
 public ActionResult Edit(Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProductTypeId = new SelectList(db.ProductTypes, "Id", "Name", product.ProductTypeId);
     return(View(product));
 }
Example #10
0
        public ActionResult Edit(CreateRoleModel model)
        {
            if (!String.IsNullOrEmpty(model.Name))
            {
                var role = AutoMapper.Mapper.Map <CreateRoleModel, IdentityRole>(model);
                context.Entry(role).State = System.Data.Entity.EntityState.Modified;
                context.SaveChanges();

                return(RedirectToAction("Management"));
            }
            return(View(model));
        }
 public ActionResult Edit([Bind(Include = "Id,Name,FactoryId,NoEmployee,Order")] TeamModel team)
 {
     if (ModelState.IsValid)
     {
         Team t = new Team
         {
             Id         = team.Id,
             Name       = team.Name,
             FactoryId  = team.FactoryId,
             NoEmployee = team.NoEmployee,
             Order      = team.Order
         };
         db.Entry(t).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.FactoryId = new SelectList(db.Factories, "Id", "Name", team.FactoryId);
     return(View(team));
 }
Example #12
0
 public void Load <TElement>(Team team, Expression <Func <Team, ICollection <TElement> > > includeProperty) where TElement : class
 {
     _context.Teams.Attach(team);
     _context.Entry(team).Collection(includeProperty).Load();
 }
 public void Load <TElement>(Goal goal, Expression <Func <Goal, ICollection <TElement> > > includeProperty) where TElement : class
 {
     _context.Goals.Attach(goal);
     _context.Entry(goal).Collection(includeProperty).Load();
 }
Example #14
0
 public void Load <TElement>(LatestSummary latestSummary, Expression <Func <LatestSummary, ICollection <TElement> > > includeProperty) where TElement : class
 {
     _context.LatestSummaries.Attach(latestSummary);
     _context.Entry(latestSummary).Collection(includeProperty).Load();
 }
        public ActionResult _Edit(QCReport qcReport)
        {
            if (qcReport.Errors != null)
            {
                foreach (var error in qcReport.Errors.ToList())
                {
                    if (!Utilities.IsNullOrDefault(error) && !error.IsDeleted)
                    {
                        db.Entry(error).State = error.Id == 0 ? EntityState.Added : EntityState.Modified;
                    }
                    else
                    {
                        qcReport.Errors.Remove(error);
                        if (error.Id != 0)
                        {
                            db.Entry(error).State = EntityState.Deleted;
                        }
                    }
                }
            }

            if (qcReport.Specifications != null)
            {
                foreach (var spec in qcReport.Specifications.ToList())
                {
                    //Xử lý SpecDetails
                    if (spec.QCSpecDetails != null)
                    {
                        foreach (var specDetail in spec.QCSpecDetails.ToList())
                        {
                            specDetail.QCSpecificationId = spec.Id;
                            if (!Utilities.IsNullOrDefault(specDetail) && !specDetail.IsDeleted)
                            {
                                db.Entry(specDetail).State = specDetail.Id == 0 ? EntityState.Added : EntityState.Modified;
                            }
                            else
                            {
                                spec.QCSpecDetails.Remove(specDetail);
                                if (specDetail.Id != 0)
                                {
                                    db.Entry(specDetail).State = EntityState.Deleted;
                                }
                            }
                        }
                    }

                    if (!spec.IsDeleted)
                    {
                        db.Entry(spec).State = spec.Id == 0 ? EntityState.Added : EntityState.Modified;
                    }
                    else
                    {
                        qcReport.Specifications.Remove(spec);
                        if (spec.Id != 0)
                        {
                            db.Entry(spec).State = EntityState.Deleted;
                        }
                    }
                }
            }

            if (db.QCReports.Any(qcr => qcr.TeamId == qcReport.TeamId && qcr.Date == qcReport.Date && qcr.QCId == qcReport.QCId))
            {
                db.Entry(qcReport).State = EntityState.Modified;
            }
            else
            {
                db.Entry(qcReport).State = EntityState.Added;
            }

            db.SaveChanges();
            return(Json(new { success = true, teamId = qcReport.TeamId, date = qcReport.Date.ToString("dd/MM/yyyy") }));
        }
Example #16
0
 public void Load <TElement>(ProduceHistory produceHistory, Expression <Func <ProduceHistory, ICollection <TElement> > > includeProperty) where TElement : class
 {
     _context.ProduceHistories.Attach(produceHistory);
     _context.Entry(produceHistory).Collection(includeProperty).Load();
 }
 public void Load <TElement>(Employee employee, Expression <Func <Employee, ICollection <TElement> > > includeProperty) where TElement : class
 {
     _context.Employees.Attach(employee);
     _context.Entry(employee).Collection(includeProperty).Load();
 }