示例#1
0
        public ResponseVM Update(EmployeeEmployeeTypeVM employeeEmployeeTypeVM)
        {
            using (context)
            {
                using (var dbTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        EmployeeEmployeeType employeeEmployeeTypeTobeUpdated = context.EmployeeEmployeeTypes.Where(x => x.EmployeeEmployeeTypeid == Guid.Parse(employeeEmployeeTypeVM.EmployeeEmployeeTypeid)).FirstOrDefault();


                        if (employeeEmployeeTypeTobeUpdated == null)
                        {
                            return(new ResponseVM("update", false, "EmployeeEmployeeType", ResponseVM.DOES_NOT_EXIST));
                        }

                        employeeEmployeeTypeTobeUpdated.EmployeeTypeid = Guid.Parse(employeeEmployeeTypeVM.EmployeeTypeid);
                        context.SaveChanges();

                        var removeFromTypeEmployees = context.TypeEmployees.Where(x => x.EmployeeEmployeeTypeid == employeeEmployeeTypeTobeUpdated.EmployeeEmployeeTypeid);
                        context.TypeEmployees.RemoveRange(removeFromTypeEmployees);
                        context.SaveChanges();


                        foreach (var empID in employeeEmployeeTypeVM.EmployeeIdList)
                        {
                            var employee = context.Employees.Find(empID);
                            if (employee == null)
                            {
                                return(new ResponseVM("create", false, "EmployeeEmployeeType", "Employee does not exists"));
                            }
                            var typeEmployee = new TypeEmployee
                            {
                                EmployeeID             = empID,
                                EmployeeEmployeeTypeid = employeeEmployeeTypeTobeUpdated.EmployeeEmployeeTypeid,
                                EmployeeFullName       = toViewModel.ToFullName(employee.FirstName, employee.LastName)
                            };

                            context.TypeEmployees.Add(typeEmployee);
                            context.SaveChanges();
                        }

                        dbTransaction.Commit();
                        return(new ResponseVM("updated", true, "EmployeeEmployeeType"));
                    }
                    catch (Exception ex)
                    {
                        dbTransaction.Rollback();
                        return(new ResponseVM
                                   ("updated", false, "EmployeeEmployeeType", ResponseVM.SOMETHING_WENT_WRONG, "", ex));

                        throw;
                    }
                }
            }
        }
示例#2
0
        public JsonResult Save_CategoryEmployee(TypeEmployee[] categoryemployee)
        {
            var value = 0;

            try
            {
                if (categoryemployee[0].Id > 0)
                {
                    var update = db.TypeEmployees.Find(categoryemployee[0].Id);
                    update.TE_Name        = categoryemployee[0].TE_Name;
                    update.TE_Admin_Staff = categoryemployee[0].TE_Admin_Staff;
                    update.TE_Note        = categoryemployee[0].TE_Note;
                    db.SaveChanges();
                    value = categoryemployee[0].Id;
                }
                else
                {
                    var categoryemployeenew = new TypeEmployee();
                    var layid = (from TE in db.TypeEmployees
                                 where TE.Id > 0
                                 orderby TE.Id descending
                                 select new
                    {
                        Id_categoryemployee = TE.Id
                    }).Take(1).ToArray();

                    if (layid.Any())
                    {
                        categoryemployeenew.Id = layid[0].Id_categoryemployee + 1;
                    }
                    else
                    {
                        categoryemployeenew.Id = 1;
                    }
                    categoryemployeenew.TE_Name        = categoryemployee[0].TE_Name;
                    categoryemployeenew.TE_Admin_Staff = categoryemployee[0].TE_Admin_Staff;
                    categoryemployeenew.TE_Note        = categoryemployee[0].TE_Note;
                    categoryemployeenew.TE_Active      = true;
                    db.TypeEmployees.Add(categoryemployeenew);
                    db.SaveChanges();
                    value = categoryemployeenew.Id;
                }
            }
            catch (Exception)
            {
                value = 0;
            }
            return(Json(value, JsonRequestBehavior.AllowGet));
        }
示例#3
0
        public ResponseVM Create(EmployeeEmployeeTypeVM employeeEmployeeTypeVM)
        {
            using (context)
            {
                using (var dbTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        employeeEmployeeTypeVM.EmployeeEmployeeTypeid = Guid.NewGuid().ToString();
                        var employeeEmployeeTypeSaved = context.EmployeeEmployeeTypes.Add(toModel.EmployeeEmployeeType(employeeEmployeeTypeVM)).Entity;
                        context.SaveChanges();

                        foreach (var empID in employeeEmployeeTypeVM.EmployeeIdList)
                        {
                            var employee = context.Employees.Find(empID);
                            if (employee == null)
                            {
                                return(new ResponseVM("create", false, "EmployeeEmployeeType", "Employee does not exists"));
                            }
                            var typeEmployee = new TypeEmployee
                            {
                                EmployeeID             = empID,
                                EmployeeEmployeeTypeid = employeeEmployeeTypeSaved.EmployeeEmployeeTypeid,
                                EmployeeFullName       = toViewModel.ToFullName(employee.FirstName, employee.LastName)
                            };

                            context.TypeEmployees.Add(typeEmployee);
                            context.SaveChanges();
                        }


                        dbTransaction.Commit();
                        return(new ResponseVM
                                   ("create", true, "EmployeeEmployeeType"));
                    }
                    catch (Exception ex)
                    {
                        dbTransaction.Rollback();
                        return(new ResponseVM("create", false, "EmployeeEmployeeType", ResponseVM.SOMETHING_WENT_WRONG, "", ex));
                    }
                }
            }
        }
示例#4
0
        public Employee(int id, string name, string surname, string patronymic, DateTime dateBirth,
                        DateTime dateEmployment, string description, TypeEmployee typeEmployee, bool isTied = false,
                        List <int> list = null)
        {
            Id             = id;
            Name           = name;
            Surname        = surname;
            Patronymic     = patronymic;
            DateBirth      = dateBirth;
            DateEmployment = dateEmployment;
            Description    = description;
            Type           = typeEmployee;
            IsTied         = isTied;

            if (list != null)
            {
                IdsEmployees.AddRange(list);
            }
        }