Inheritance: System.Web.UI.Page
        public Result <ApplicationResult <DepartmentDto> > Create(DepartmentCreateDto departmentDto)
        {
            var applicationResult = new ApplicationResult <DepartmentDto>();

            _codeBuilder.Build("DE1", "DE")
            .OnSuccess(resultCode => DepartmentEdit.Create(resultCode, departmentDto.Name, departmentDto.Description))
            .OnSuccess(resultDepartment => {
                if (resultDepartment.IsValid)
                {
                    _departmentRepository.Create(resultDepartment)
                    .OnSuccess(() =>
                    {
                        var dto = Mapper.Map <DepartmentDto>(resultDepartment);

                        applicationResult.IsValid = true;
                        applicationResult.Entity  = dto;
                    });
                }
                else
                {
                    applicationResult.IsValid = false;
                    foreach (var error in resultDepartment.BrokenRules.Errors)
                    {
                        applicationResult.ErrorMessages.Add(new ErrorMessage {
                            Code = error.ErrorCode, Message = error.ErrorMessage
                        });
                    }
                }
            });

            return(applicationResult.ToResult());
        }
        private Result <ApplicationResult <DepartmentDto> > UpdateModel(DepartmentEdit departmentEdit, DepartmentUpdateDto departmentUpdateDto)
        {
            var applicationResult = new ApplicationResult <DepartmentDto>();

            DepartmentEdit.Update(departmentEdit, departmentUpdateDto.Name, departmentUpdateDto.Description)
            .OnSuccess(resultDepartment => {
                if (resultDepartment.IsValid)
                {
                    _departmentRepository.Update(resultDepartment)
                    .OnSuccess(() => {
                        var dto = Mapper.Map <DepartmentDto>(resultDepartment);

                        applicationResult.IsValid = true;
                        applicationResult.Entity  = dto;
                    });
                }
                else
                {
                    applicationResult.IsValid = false;
                    foreach (var error in resultDepartment.BrokenRules.Errors)
                    {
                        applicationResult.ErrorMessages.Add(new ErrorMessage {
                            Code = error.ErrorCode, Message = error.ErrorMessage
                        });
                    }
                }
            });

            return(applicationResult.ToResult());
        }
        public ActionResult New()
        {
            //need to give a list of the hospitals so that they can select the one they want
            var deptedit = new DepartmentEdit();

            deptedit.Hospitals = db.Hospitals.ToList();

            return(View(deptedit));
        }
 public void EditDepartmentApplicaiton()
 {
     DepartmentEdit.ClickOn();
     DepartmentName.Clear();
     DepartmentConfirm.ClickOn();
     softAssert.VerifyElementIsPresent(DepNameValidationPopup);
     DepartmentName.EnterClearText(Constant.departmentName + RandomNumber.smallNumber());
     DepartmentConfirm.ClickOn();
 }
        public ActionResult Edit(int id)
        {
            DepartmentEdit depeditview = new DepartmentEdit();

            depeditview.Hospitals   = db.Hospitals.ToList();
            depeditview.Departments = db.Departments.Include(h => h.Hospital).SingleOrDefault(d => d.DepartmentID == id); //finds all department

            //GOTO: Views/Job/Edit.cshtml
            return(View(depeditview));
        }
Example #6
0
        private void Insert()
        {
            if (this.editChild == null)
            {
                this.editChild = new DepartmentEdit();
                PageAnimation.back.Children.Add(this.editChild);
            }

            Messenger.Default.Send(new ChildMessage()
            {
                currentObject = null, isEdit = false, action = ActionMenuButton.Insert, level = "Main"
            });
            PageAnimation.ToBack();
        }
Example #7
0
        private void View()
        {
            if (this.editChild == null)
            {
                this.editChild = new DepartmentEdit();
                PageAnimation.back.Children.Add(this.editChild);
            }

            Messenger.Default.Send(new ChildMessage()
            {
                currentObject = this.currentSelectItem.ItemContent, isEdit = false, action = ActionMenuButton.View, level = "Main"
            });
            PageAnimation.ToBack();
        }
Example #8
0
        public Result <DepartmentEdit> Create(DepartmentEdit entity)
        {
            var document = new BsonDocument
            {
                { "id", entity.Id },
                { "code", entity.Code },
                { "name", entity.Name },
                { "description", entity.Description },
                { "status", entity.Status }
            };

            collection.InsertOne(document);

            return(entity.ToResult());
        }
        public bool UpdateDepartment(DepartmentEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Departments
                    .Single(e => e.DeptId == model.DeptId);
                entity.DeptId     = model.DeptId;
                entity.DeptName   = model.DeptName;
                entity.BuildingId = model.BuildingId;
                entity.Location   = model.Location;
                entity.Room       = model.Room;

                return(ctx.SaveChanges() == 1);
            }
        }
Example #10
0
        public ActionResult Create(DepartmentEdit department)
        {
            if (ModelState.IsValid)
            {
                var item = db.Departments.Create();

                item.InjectFrom(department);

                db.Departments.Add(item);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            ViewBag.InstructorID = new SelectList(db.People, "ID", "FirstName");

            return(View(department));
        }
Example #11
0
        public ActionResult Edit(int ID, DepartmentEdit department)
        {
            if (ModelState.IsValid)
            {
                var item = repo.Get單一筆部門資料(ID);
                item.InjectFrom(department);
                //item.Name = department.Name;
                //item.Budget = department.Budget;
                //item.StartDate = department.StartDate;
                //item.InstructorID = department.InstructorID;
                repo.UnitOfWork.Commit();
                return(RedirectToAction("Index"));
            }
            var dept = repo.Get單一筆部門資料(ID);

            ViewBag.InstructorID = new SelectList(repoPerson.All(), "ID", "FirstName", dept.InstructorID);
            return(View(dept));
        }
Example #12
0
        public ActionResult Edit(int id, DepartmentEdit department)
        {
            if (ModelState.IsValid)
            {
                var item = db.Department.Find(id);

                item.InjectFrom(department);

                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            var dept = db.Department.Find(id);

            ViewBag.InstructorID = new SelectList(db.Person, "ID", "FirstName", dept.InstructorID);

            return(View(department));
        }
Example #13
0
        public ActionResult Edit(int id, DepartmentEdit department)
        {
            if (ModelState.IsValid)
            {
                var item = repo.GetOne(id);

                item.InjectFrom(department);

                repo.UnitOfWork.Commit();

                return(RedirectToAction("Index"));
            }

            var dept = repo.GetOne(id);

            ViewBag.InstructorID = new SelectList(repoPerson.All(), "ID", "FirstName", dept.InstructorID);

            return(View(dept));
        }
        public ActionResult Edit(int id, DepartmentEdit department)
        {
            if (ModelState.IsValid)
            {
                var item = db.Department.Find(id);
                item.InjectFrom(department);  //會比對兩個model是否型別一致!不一至就不會被寫入
                //item.Name = department.Name;
                //item.Budget = department.Budget;
                //item.StartDate = department.StartDate;
                //item.InstructorID = department.InstructorID;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            var dept = db.Department.Find(id);

            ViewBag.InstructorID = new SelectList(db.Person.Where(c => c.Discriminator == "Instructor"), "ID", "FirstName", dept.InstructorID);

            return(View(dept));
        }
        public ActionResult Edit(int id, DepartmentEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.DeptId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }
            var service = CreateDepartmentService();

            if (service.UpdateDepartment(model))
            {
                TempData["SaveResult"] = "The department was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "The department could not be updated.");
            return(View(model));
        }
Example #16
0
        public ActionResult Edit(int id, DepartmentEdit department)
        {
            if (ModelState.IsValid)
            {
                var item = db.Department.Find(id);

                item.InjectFrom(department);
                //item.Name = department.Name;
                //item.Budget = department.Budget;
                //item.StartDate = department.StartDate;
                //item.InstructorID = department.InstructorID;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            //ViewBag.InstructorID = new SelectList(db.Person, "ID", "FirstName");

            var dept = db.Department.Find(id);

            ViewBag.InstructorID = new SelectList(db.Person.OrderBy(p => p.FirstName), "ID", "FirstName", dept.InstructorID);

            return(View(dept));
        }
Example #17
0
        public ActionResult Edit(DepartmentEdit department)
        {
            if (ModelState.IsValid)
            {
                var item = db.Departments.Find(department.DepartmentID);

                // 用inject注入
                item.InjectFrom(department);

                //item.Name = department.Name;
                //item.Budget = department.Budget;
                //item.StartDate = department.StartDate;
                //item.InstructorID = department.InstructorID;

                db.Entry(item).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            ViewBag.InstructorID = new SelectList(db.People, "ID", "FirstName", department.InstructorID);
            return(View(department));
        }
        public ActionResult Edit(int id)
        {
            var             service   = CreateDepartmentService();
            var             detail    = service.GetDepartmentById(id);
            List <Building> Buildings = CreateBuildingService().GetBuildingsData().ToList();

            ViewBag.BuildingId = Buildings.Select(o => new SelectListItem()
            {
                Value    = o.BuildingId.ToString(),
                Text     = o.BuildingName,
                Selected = o.BuildingId == detail.BuildingId
            });
            var model =
                new DepartmentEdit
            {
                DeptId     = detail.DeptId,
                DeptName   = detail.DeptName,
                BuildingId = detail.BuildingId,
                Location   = detail.Location,
                Room       = detail.Room
            };

            return(View(model));
        }
Example #19
0
 public Result <DepartmentEdit> Update(DepartmentEdit entity)
 {
     throw new NotImplementedException();
 }
Example #20
0
 /// <summary>
 /// 菜单 - 编辑
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void menuEdit_Click(object sender, EventArgs e)
 {
     DepartmentEdit?.Invoke(sender, e);
 }