示例#1
0
        public ServiceResponse <m_employee> EditEmployee(m_employee model)
        {
            try
            {
                model.UpdatedBy   = "";
                model.UpdatedDate = DateTime.UtcNow;
                _ctx.m_employees.Update(model);
                _ctx.SaveChanges();

                return(new ServiceResponse <m_employee>
                {
                    IsSuccess = true,
                    Time = DateTime.UtcNow,
                    Message = "Employee Created",
                    Data = model
                });
            }
            catch (Exception e)
            {
                return(new ServiceResponse <m_employee>
                {
                    IsSuccess = false,
                    Time = DateTime.UtcNow,
                    Message = e.StackTrace,
                    Data = null
                });
            }
        }
示例#2
0
        public ServiceResponse <m_employee> CreateEmployee(m_employee model)
        {
            try
            {
                model.Code        = GenerateCode();
                model.IsDelete    = false;
                model.CreatedBy   = "Admin";
                model.CreatedDate = DateTime.UtcNow;

                _ctx.m_employees.Add(model);
                _ctx.SaveChanges();

                return(new ServiceResponse <m_employee>
                {
                    IsSuccess = true,
                    Time = DateTime.UtcNow,
                    Message = "Employee Created",
                    Data = model
                });
            }
            catch (Exception e)
            {
                return(new ServiceResponse <m_employee>
                {
                    IsSuccess = false,
                    Time = DateTime.UtcNow,
                    Message = e.StackTrace,
                    Data = null
                });
            }
        }
示例#3
0
        public static Responses Update(M_EmployeeViewModel entity)
        {
            Responses result = new Responses();

            try
            {
                using (var db = new MarcomContext())
                {
                    if (entity.Id != 0)
                    {
                        m_employee employee = db.m_employee.Where(o => o.id == entity.Id).FirstOrDefault();
                        if (employee != null)
                        {
                            employee.id = entity.Id;
                            employee.employee_number = entity.EmployeeNumber;
                            employee.first_name      = entity.FirstName;
                            employee.last_name       = entity.LastName;
                            employee.m_company_id    = entity.MCompanyId;
                            employee.email           = entity.Email;
                            employee.is_delete       = entity.IsDelete;
                            employee.updated_by      = "Ryan";
                            employee.updated_date    = DateTime.Now;
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        m_employee employee = new m_employee();
                        employee.id = entity.Id;
                        employee.employee_number = GetNewCode();
                        employee.first_name      = entity.FirstName;
                        employee.last_name       = entity.LastName;
                        employee.m_company_id    = entity.MCompanyId;
                        employee.email           = entity.Email;
                        employee.is_delete       = false;
                        employee.created_by      = "Ryan";
                        employee.created_date    = DateTime.Now;
                        db.m_employee.Add(employee);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Success = false;
            }
            return(result);
        }
示例#4
0
        public static bool Delete(int id)
        {
            bool result = false;

            using (AppEntity db = new AppEntity())
            {
                m_employee item = db.m_employee.Find(id);
                item.is_active    = false;
                item.updated_by   = 1;
                item.updated_date = DateTime.Now;
                try { db.SaveChanges(); result = true; } catch (Exception) { throw; }
            }

            return(result);
        }
示例#5
0
 public static employeeViewModel SerializeEmployee(m_employee model)
 {
     return(new employeeViewModel
     {
         Id = model.Id,
         Code = model.Code,
         FirstName = model.FirstName,
         LastName = model.LastName,
         MCompany = CompanyMapper.SerializeCompany(model.MCompany),
         Email = model.Email,
         IsDelete = model.IsDelete,
         CreatedBy = model.CreatedBy,
         CreatedDate = model.CreatedDate,
         UpdatedBy = model.UpdatedBy,
         UpdatedDate = model.UpdatedDate
     });
 }
示例#6
0
        public static bool update(MEmployeeVM model)
        {
            bool result = false;

            using (AppEntity db = new AppEntity())
            {
                m_employee item = db.m_employee.Find(model.id);
                item.employee_number = model.employee_number;
                item.first_name      = model.first_name;
                item.last_name       = model.last_name;
                item.m_company_id    = model.m_company_id;

                item.email        = model.email;
                item.is_active    = true;
                item.created_by   = 1;
                item.created_date = DateTime.Now;
                try { db.SaveChanges(); result = true; } catch (Exception) { throw; }
            }
            return(result);
        }
        //public static List<EmployeeViewModel> GetListEmployee(EmployeeViewModel paramSearch)
        //{
        //    List<EmployeeViewModel> result = new List<EmployeeViewModel>();

        //    using (var context = new MarkomApplicationDBEntities())
        //    {
        //        var res = context.spEmployeeSearch(paramSearch.code, paramSearch.fullName,paramSearch.mCompanyId, paramSearch.createDate2, paramSearch.createBy);

        //        List<EmployeeViewModel> comList = res.Select(c => new EmployeeViewModel
        //        {
        //            id = c.id,
        //            code = c.employee_number,
        //            firstName = c.first_name,
        //            lastName = c.last_name,
        //            mCompanyId = c.m_company_id,
        //            companyName = c.name,
        //            createDate = c.create_date,
        //            createBy = c.create_by
        //        }).ToList();

        //        result = comList;
        //    }

        //    return result;
        //}

        //CREATE EMPLOYEE


        public static string CreateEmployee(EmployeeViewModel paramDataEmployee)
        {
            string latestSaveCode = string.Empty;

            using (var db = new MarkomApplicationDBEntities())
            {
                using (var dbContextTransaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        m_employee c = new m_employee();
                        c.employee_number = paramDataEmployee.code;
                        c.first_name      = paramDataEmployee.firstName;
                        c.last_name       = paramDataEmployee.lastName;
                        c.m_company_id    = paramDataEmployee.mCompanyId;
                        c.email           = paramDataEmployee.email;
                        c.is_delete       = paramDataEmployee.isDelete;
                        c.create_by       = paramDataEmployee.createBy;
                        c.create_date     = paramDataEmployee.createDate;

                        db.m_employee.Add(c);
                        db.SaveChanges();
                        dbContextTransaction.Commit();

                        //get latest save code
                        latestSaveCode = c.employee_number;
                    }
                    catch (Exception ex)
                    {
                        Message = ex.Message;
                        dbContextTransaction.Rollback();
                        //throw;
                    }
                }
            }

            return(latestSaveCode);
        }
示例#8
0
        public static Responses Delete(int id)
        {
            Responses result = new Responses();

            try
            {
                using (var db = new MarcomContext())
                {
                    m_employee employee = db.m_employee.Where(o => o.id == id).FirstOrDefault();
                    if (employee != null)
                    {
                        employee.is_delete = true;
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Success = false;
            }
            return(result);
        }
示例#9
0
        public static bool insert(MEmployeeVM model)
        {
            bool result = false;

            using (AppEntity db = new AppEntity())
            {
                m_employee item = new m_employee()
                {
                    employee_number = model.employee_number,
                    first_name      = model.first_name,
                    last_name       = model.last_name,
                    m_company_id    = model.m_company_id,
                    email           = model.email,

                    is_active    = true,
                    created_by   = 1,
                    created_date = DateTime.Now
                };
                db.m_employee.Add(item);
                try { db.SaveChanges(); result = true; } catch (Exception) { throw; }
            }
            return(result);
        }