コード例 #1
0
        public static M_CompanyViewModel GetById(int id)
        {
            M_CompanyViewModel result = new M_CompanyViewModel();

            using (var db = new MarcomContext())
            {
                result = (from c in db.m_company
                          where c.id == id
                          select new M_CompanyViewModel
                {
                    Id = c.id,
                    Code = c.code,
                    Name = c.name,
                    Address = c.address,
                    Phone = c.phone,
                    Email = c.email,
                    IsDelete = c.is_delete,
                    CreatedBy = c.created_by,
                    CreatedDate = c.created_date,
                    UpdatedBy = c.updated_by,
                    UpdatedDate = c.updated_date
                }).FirstOrDefault();
            }
            return(result);
        }
コード例 #2
0
        public static List <M_UserViewModel> Get()
        {
            List <M_UserViewModel> result = new List <M_UserViewModel>();

            using (var db = new MarcomContext())
            {
                result = (from u in db.m_user
                          join e in db.m_employee on
                          u.m_employee_id equals e.id
                          join r in db.m_role on
                          u.m_role_id equals r.id
                          join c in db.m_company on
                          e.m_company_id equals c.id
                          where u.is_delete == false
                          select new M_UserViewModel
                {
                    Id = u.id,
                    Username = u.username,
                    Password = u.password,
                    MRoleId = u.m_role_id,
                    RoleName = r.name,
                    MEmployeeId = e.id,
                    FirstName = e.first_name,
                    LastName = e.last_name,
                    MCompanyId = c.id,
                    CompanyName = c.name,
                    CreatedBy = u.created_by,
                    CreatedDate = u.created_date,
                    IsDelete = u.is_delete
                }).ToList();
            }
            return(result);
        }
コード例 #3
0
        public static M_SouvenirViewModel GetById(int id)
        {
            M_SouvenirViewModel result = new M_SouvenirViewModel();

            using (var db = new MarcomContext())
            {
                result = (from s in db.m_souvenir
                          join u in db.m_unit on
                          s.m_unit_id equals u.id
                          where s.id == id
                          select new M_SouvenirViewModel
                {
                    Id = s.id,
                    Code = s.code,
                    Name = s.name,
                    Description = s.description,
                    mUnitId = s.m_unit_id,
                    unitName = u.name,
                    Created_by = s.created_by,
                    Created_date = s.created_date,
                    isDelete = s.is_delete
                }).FirstOrDefault();
            }
            return(result);
        }
コード例 #4
0
        //public static string[] SplitCode(string data)
        //{
        //    string numbers = "";
        //    string alpha = "";
        //    foreach (char c in data)
        //    {
        //        if (Char.IsDigit(c))
        //        {
        //            numbers = numbers + c;
        //        }
        //        else if (Char.IsLetter(c))
        //        {
        //            alpha = alpha + c;
        //        }
        //    }
        //    return new string[] { numbers, alpha };
        //}
        public static List <M_EmployeeViewModel> Get()
        {
            List <M_EmployeeViewModel> result = new List <M_EmployeeViewModel>();

            using (var db = new MarcomContext())
            {
                result = (from e in db.m_employee
                          join c in db.m_company on
                          e.m_company_id equals c.id
                          where e.is_delete == false
                          select new M_EmployeeViewModel
                {
                    Id = e.id,
                    EmployeeNumber = e.employee_number,
                    FirstName = e.first_name,
                    LastName = e.last_name,
                    MCompanyId = c.id,
                    MCompanyName = c.name,
                    Email = e.email,
                    CreatedBy = e.created_by,
                    CreatedDate = e.created_date,
                    IsDelete = e.is_delete
                }).ToList();
            }
            return(result);
        }
コード例 #5
0
        public static T_PromotionItemFileViewModel GetById(int id)
        {
            T_PromotionItemFileViewModel result = new T_PromotionItemFileViewModel();

            using (var db = new MarcomContext())
            {
                result = (from pif in db.t_promotion_item_file
                          where pif.id == id
                          select new T_PromotionItemFileViewModel
                {
                    Id = pif.id,
                    TPromotionId = pif.t_promotion_id,
                    FileName = pif.filename,
                    Size = pif.size,
                    Extention = pif.extention,
                    StartDate = pif.start_date,
                    EndDate = pif.end_date,
                    RequestDueDate = pif.request_due_date,
                    Qty = pif.qty,
                    Todo = pif.todo,
                    Note = pif.note
                }).FirstOrDefault();
            }
            return(result);
        }
コード例 #6
0
        public static string GetNewCode()
        {
            int    newIncrement = 1;
            string newCode      = string.Format("TRWODS{0}{1}{2}", DateTime.Now.Day.ToString("D2"), DateTime.Now.Month.ToString("D2"), DateTime.Now.ToString("yy"));

            using (var db = new MarcomContext())
            {
                var result = (from d in db.t_design
                              where d.code.Contains(newCode)
                              select new { tcode = d.code })
                             .OrderByDescending(o => o.tcode)
                             .FirstOrDefault();
                if (result != null)
                {
                    string rcode = result.tcode.ToString();
                    string c1    = rcode.Substring(0, 6);
                    string c2    = rcode.Substring(6, 6);
                    string c3    = rcode.Substring(12, 5);
                    newIncrement = int.Parse(c3) + 1;
                }
            }
            newCode += newIncrement.ToString("D5");
            string code = newCode.Replace(".", "");

            return(code);
        }
コード例 #7
0
        public static T_PromotionItemViewModel GetById(int id)
        {
            T_PromotionItemViewModel result = new T_PromotionItemViewModel();

            using (var db = new MarcomContext())
            {
                result = (from p in db.t_promotion_item
                          select new T_PromotionItemViewModel
                {
                    Id = p.id,
                    TPromotionId = p.t_promotion_id,
                    TDesignItemId = p.t_design_item_id,
                    MProductId = p.m_product_id,
                    Title = p.title,
                    RequestPic = p.request_pic,
                    StartDate = p.start_date,
                    EndDate = p.end_date,
                    RequestDueDate = p.request_due_date,
                    Qty = p.qty,
                    ToDo = p.todo,
                    Note = p.note,
                    isDelete = p.is_delete,
                    CreatedBy = p.created_by,
                    CreatedDate = p.created_date
                }).FirstOrDefault();
            }
            return(result);
        }
コード例 #8
0
        public static List <T_PromotionItemFileViewModel> Get()
        {
            List <T_PromotionItemFileViewModel> result = new List <T_PromotionItemFileViewModel>();

            using (var db = new MarcomContext())
            {
                result = (from pif in db.t_promotion_item_file
                          where pif.is_delete == false
                          select new T_PromotionItemFileViewModel
                {
                    Id = pif.id,
                    TPromotionId = pif.t_promotion_id,
                    FileName = pif.filename,
                    Size = pif.size,
                    Extention = pif.extention,
                    StartDate = pif.start_date,
                    EndDate = pif.end_date,
                    RequestDueDate = pif.request_due_date,
                    Qty = pif.qty,
                    Todo = pif.todo,
                    Note = pif.note
                }).ToList();
            }
            return(result);
        }
コード例 #9
0
        public static List <T_DesignViewModel> Get()
        {
            List <T_DesignViewModel> result = new List <T_DesignViewModel>();

            using (var db = new MarcomContext())
            {
                result = (from d in db.t_design
                          join ev in db.t_event on
                          d.t_event_id equals ev.id
                          join e in db.m_employee on
                          d.request_by equals e.id
                          select new T_DesignViewModel
                {
                    Id = d.id,
                    Code = d.code,
                    RequestBy = d.request_by,
                    FirstName = e.first_name,
                    LastName = e.last_name,
                    RequestDate = d.request_date,
                    AssignTo = d.assign_to,
                    Status = d.status,
                    IsDelete = d.is_delete,
                    CreatedBy = d.created_by,
                    CreatedDate = d.created_date
                }).ToList();
            }
            return(result);
        }
コード例 #10
0
        public static Responses Delete(int Id)
        {
            Responses result = new Responses();

            try
            {
                using (var db = new MarcomContext())
                {
                    m_product m_product = db.m_product.Where(o => o.id == Id).FirstOrDefault();

                    if (m_product != null)
                    {
                        m_product.is_delete = true;
                        db.SaveChanges();
                    }
                }
            }

            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Success = false;
            }

            return(result);
        }
コード例 #11
0
        public static List <M_SouvenirViewModel> Get()
        {
            List <M_SouvenirViewModel> result = new List <M_SouvenirViewModel>();

            using (var db = new MarcomContext())
            {
                result = (from s in db.m_souvenir
                          join u in db.m_unit on
                          s.m_unit_id equals u.id
                          where s.is_delete == false
                          select new M_SouvenirViewModel
                {
                    Id = s.id,
                    Code = s.code,
                    Name = s.name,
                    Description = s.description,
                    mUnitId = s.m_unit_id,
                    unitName = u.name,
                    Created_by = s.created_by,
                    Created_date = s.created_date,
                    isDelete = s.is_delete
                }).ToList();
            }
            return(result);
        }
コード例 #12
0
        public static List <T_SouvinerItemViewModel> Get()
        {
            List <T_SouvinerItemViewModel> result = new List <T_SouvinerItemViewModel>();

            using (var db = new MarcomContext())
            {
                result = (from tsi in db.t_souvenir_item
                          join ts in db.t_souvenir on
                          tsi.t_souvenir_id equals ts.id
                          join ms in db.m_souvenir on
                          tsi.m_souvenir_id equals ms.id
                          select new T_SouvinerItemViewModel
                {
                    Id = tsi.id,

                    TransactionCode = ts.code,          // Table t_souvenir_item
                    RequestBy = ts.request_by,
                    RequestDate = ts.request_date,
                    DueDate = ts.request_due_date,

                    Qty = tsi.qty,
                    QtySettlement = tsi.qty_settlement,
                    Note = tsi.note,
                    IsDelete = tsi.is_delete,
                    CreatedBy = tsi.created_by,
                    CreatedDate = tsi.created_date,
                    UpdatedBy = tsi.updated_by,
                    UpdatedDate = tsi.updated_date,
                }).ToList();
            }
            return(result);
        }
コード例 #13
0
        public static List <M_CompanyViewModel> Get()
        {
            List <M_CompanyViewModel> result = new List <M_CompanyViewModel>();

            using (var db = new MarcomContext())
            {
                result = (from c in db.m_company
                          where c.is_delete == false
                          select new M_CompanyViewModel
                {
                    Id = c.id,
                    Code = c.code,
                    Name = c.name,
                    Address = c.address,
                    Phone = c.phone,
                    Email = c.email,
                    IsDelete = c.is_delete,
                    CreatedBy = c.created_by,
                    CreatedDate = c.created_date,
                    UpdatedBy = c.updated_by,
                    UpdatedDate = c.updated_date
                }).ToList();
            }
            return(result);
        }
コード例 #14
0
        public static M_UserViewModel GetById(int id)
        {
            M_UserViewModel result = new M_UserViewModel();

            using (var db = new MarcomContext())
            {
                result = (from u in db.m_user
                          join r in db.m_role on
                          u.m_role_id equals r.id
                          join e in db.m_employee on
                          u.m_employee_id equals e.id
                          join c in db.m_company on
                          e.m_company_id equals c.id
                          where u.id == id
                          select new M_UserViewModel
                {
                    Id = u.id,
                    Username = u.username,
                    Password = u.password,
                    MRoleId = u.m_role_id,
                    RoleName = r.name,
                    MEmployeeId = e.id,
                    FirstName = e.first_name,
                    MCompanyId = c.id,
                    CompanyName = c.name,
                    CreatedBy = u.created_by,
                    CreatedDate = u.created_date,
                    IsDelete = false
                }).FirstOrDefault();
            }
            return(result);
        }
コード例 #15
0
        public static List <M_EmployeeViewModel> GetByEmployeId(int id)
        {
            List <M_EmployeeViewModel> result = new List <M_EmployeeViewModel>();

            using (var db = new MarcomContext())
            {
                {
                    result = (from e in db.m_employee
                              join u in db.m_user on
                              e.id equals u.m_employee_id
                              into temp
                              from x in temp.DefaultIfEmpty() //e.id  equals  u.m_employee_id //u.is_delete == 0
                              where temp.Count() == 0 || e.id == id
                              select new M_EmployeeViewModel
                    {
                        Id = e.id,
                        //= (x.m_employee_id == null? "null" : x.m_employee_id),
                        FirstName = e.first_name,
                        LastName = e.last_name,
                        IsDelete = false
                    }).ToList();
                }
            }
            return(result);
        }
コード例 #16
0
        public static T_DesignItemViewModel GetById(int id)
        {
            T_DesignItemViewModel result = new T_DesignItemViewModel();

            using (var db = new MarcomContext())
            {
                result = (from di in db.t_design_item
                          join d in db.t_design on
                          di.t_design_id equals d.id
                          join p in db.m_product on
                          di.m_product_id equals p.id
                          select new T_DesignItemViewModel
                {
                    Id = di.id,
                    TDesignId = d.id,
                    MProductId = di.m_product_id,
                    TitleItem = di.title_item,
                    RequestPic = di.request_pic,
                    StartDate = di.start_date,
                    EndDate = di.end_date,
                    RequestDueDate = di.request_due_date,
                    Note = di.note,
                    IsDelete = di.is_delete,
                    CreatedBy = di.created_by,
                    CreatedDate = di.created_date,
                    UpdatedBy = di.updated_by,
                    UpdatedDate = di.updated_date
                }).FirstOrDefault();
            }
            return(result);
        }
コード例 #17
0
        public static T_DesignViewModel GetById(int id)
        {
            T_DesignViewModel result = new T_DesignViewModel();

            using (var db = new MarcomContext())
            {
                result = (from d in db.t_design
                          where d.id == id
                          select new T_DesignViewModel
                {
                    Id = d.id,
                    Code = d.code,
                    TitleHeader = d.title_header,
                    RequestBy = d.request_by,
                    RequestDate = d.request_date,
                    AssignTo = d.assign_to,
                    Status = d.status,
                    Note = d.note,
                    IsDelete = d.is_delete,
                    CreatedBy = d.created_by,
                    CreatedDate = d.created_date
                }).FirstOrDefault();
            }
            return(result);
        }
コード例 #18
0
        public static Responses Update(T_PromotionItemFileViewModel entity)
        {
            Responses result = new Responses();

            try
            {
                using (var db = new MarcomContext())
                {
                    if (entity.Id != 0)
                    {
                        t_promotion_item_file tpifile = db.t_promotion_item_file.Where(tpif => tpif.id == entity.Id).FirstOrDefault();
                        if (tpifile != null)
                        {
                            tpifile.t_promotion_id   = entity.TPromotionId;
                            tpifile.filename         = entity.FileName;
                            tpifile.size             = entity.Size;
                            tpifile.extention        = entity.Extention;
                            tpifile.start_date       = entity.StartDate;
                            tpifile.end_date         = entity.EndDate;
                            tpifile.request_due_date = entity.RequestDueDate;
                            tpifile.qty          = entity.Qty;
                            tpifile.todo         = entity.Todo;
                            tpifile.note         = entity.Note;
                            tpifile.is_delete    = entity.IsDelete;
                            tpifile.updated_by   = "Soleh";
                            tpifile.updated_date = DateTime.Now;
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        t_promotion_item_file tpifile = new t_promotion_item_file();
                        tpifile.t_promotion_id   = entity.TPromotionId;
                        tpifile.filename         = 0;
                        tpifile.size             = entity.Size;
                        tpifile.extention        = entity.Extention;
                        tpifile.start_date       = entity.StartDate;
                        tpifile.end_date         = entity.EndDate;
                        tpifile.request_due_date = entity.RequestDueDate;
                        tpifile.qty          = entity.Qty;
                        tpifile.todo         = entity.Todo;
                        tpifile.note         = entity.Note;
                        tpifile.is_delete    = false;
                        tpifile.created_by   = "Soleh";
                        tpifile.created_date = DateTime.Now;

                        db.t_promotion_item_file.Add(tpifile);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Success = false;
            }
            return(result);
        }
コード例 #19
0
        public static Responses Update(T_DesignViewModel entity)
        {
            Responses result = new Responses();

            try
            {
                using (var db = new MarcomContext())
                {
                    if (entity.Id != 0)
                    {
                        t_design design = db.t_design.Where(o => o.id == entity.Id).FirstOrDefault();
                        if (design != null)
                        {
                            design.code         = entity.Code;
                            design.t_event_id   = entity.TEventId;
                            design.title_header = entity.TitleHeader;
                            design.request_by   = entity.RequestBy;
                            design.request_date = entity.RequestDate;
                            design.assign_to    = entity.AssignTo;
                            design.status       = entity.Status;
                            design.note         = entity.Note;
                            design.is_delete    = false;
                            design.updated_by   = "Ryan";
                            design.updated_date = DateTime.Now;
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        t_design design = new t_design();
                        design.code         = entity.Code;
                        design.t_event_id   = entity.TEventId;
                        design.title_header = entity.TitleHeader;
                        design.request_by   = 6;
                        design.request_date = DateTime.Now;
                        design.assign_to    = null;
                        design.status       = 1;
                        design.note         = entity.Note;
                        design.is_delete    = false;
                        design.created_by   = "Ryan";
                        design.created_date = DateTime.Now;
                        db.t_design.Add(design);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Success = false;
            }
            return(result);
        }
コード例 #20
0
        public static Responses Update(T_DesignItemViewModel entity)
        {
            Responses result = new Responses();

            try
            {
                using (var db = new MarcomContext())
                {
                    if (entity.Id != 0)
                    {
                        t_design_item di = db.t_design_item.Where(o => o.id == entity.Id).FirstOrDefault();
                        if (di != null)
                        {
                            di.t_design_id      = entity.TDesignId;
                            di.m_product_id     = entity.MProductId;
                            di.title_item       = entity.TitleItem;
                            di.request_pic      = entity.RequestPic;
                            di.start_date       = entity.StartDate;
                            di.end_date         = entity.EndDate;
                            di.request_due_date = entity.RequestDueDate;
                            di.note             = entity.Note;
                            di.is_delete        = entity.IsDelete;
                            di.updated_by       = "Andra";
                            di.updated_date     = DateTime.Now;
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        t_design_item di = new t_design_item();
                        di.t_design_id      = entity.TDesignId;
                        di.m_product_id     = entity.MProductId;
                        di.title_item       = entity.TitleItem;
                        di.request_pic      = entity.RequestPic;
                        di.start_date       = entity.StartDate;
                        di.end_date         = entity.EndDate;
                        di.request_due_date = entity.RequestDueDate;
                        di.note             = entity.Note;
                        di.is_delete        = entity.IsDelete;
                        di.created_by       = "Andra";
                        di.created_date     = DateTime.Now;
                        db.t_design_item.Add(di);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Success = false;
            }
            return(result);
        }
コード例 #21
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);
        }
コード例 #22
0
        public static Responses Update(M_SouvenirViewModel entity)
        {
            Responses result = new Responses();

            try
            {
                using (var db = new MarcomContext())
                {
                    if (entity.Id != 0)
                    {
                        m_souvenir souvenir = db.m_souvenir.Where(o => o.id == entity.Id).FirstOrDefault();
                        if (souvenir != null)
                        {
                            souvenir.id           = entity.Id;
                            souvenir.code         = entity.Code;
                            souvenir.name         = entity.Name;
                            souvenir.description  = entity.Description;
                            souvenir.m_unit_id    = entity.mUnitId;
                            souvenir.is_delete    = entity.isDelete;
                            souvenir.updated_by   = "Asyam";
                            souvenir.updated_date = DateTime.Now;
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        m_souvenir souvenir = new m_souvenir();
                        souvenir.id           = entity.Id;
                        souvenir.code         = entity.Code;
                        souvenir.name         = entity.Name;
                        souvenir.description  = entity.Description;
                        souvenir.m_unit_id    = entity.mUnitId;
                        souvenir.is_delete    = false;
                        souvenir.created_by   = "Asyam";
                        souvenir.created_date = DateTime.Now;
                        db.m_souvenir.Add(souvenir);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Success = false;
            }
            return(result);
        }
コード例 #23
0
        public static Responses Update(M_CompanyViewModel entity)
        {
            Responses result = new Responses();

            try
            {
                using (var db = new MarcomContext())
                {
                    if (entity.Id != 0)
                    {
                        m_company company = db.m_company.Where(o => o.id == entity.Id).FirstOrDefault();
                        if (company != null)
                        {
                            company.code         = entity.Code;
                            company.name         = entity.Name;
                            company.address      = entity.Address;
                            company.phone        = entity.Phone;
                            company.email        = entity.Email;
                            company.is_delete    = entity.IsDelete;
                            company.updated_by   = "Andra";
                            company.updated_date = DateTime.Now;
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        m_company company = new m_company();
                        company.code         = GetNewCode();
                        company.name         = entity.Name;
                        company.address      = entity.Address;
                        company.phone        = entity.Phone;
                        company.email        = entity.Email;
                        company.is_delete    = false;
                        company.created_by   = "Andra";
                        company.created_date = DateTime.Now;
                        db.m_company.Add(company);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Success = false;
            }
            return(result);
        }
コード例 #24
0
        public static Responses Update(M_UserViewModel entity)
        {
            Responses result = new Responses();

            try
            {
                using (var db = new MarcomContext())
                {
                    if (entity.Id != 0)
                    {
                        m_user mUser = db.m_user.Where(u => u.id == entity.Id).FirstOrDefault();
                        if (mUser != null)
                        {
                            mUser.username      = entity.Username;
                            mUser.password      = entity.Password;
                            mUser.m_employee_id = entity.MEmployeeId;
                            mUser.m_role_id     = entity.MRoleId;
                            mUser.updated_by    = "Admin";
                            mUser.updated_date  = DateTime.Now;
                            mUser.is_delete     = false;
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        m_user mUser = new m_user();
                        mUser.username      = entity.Username;
                        mUser.password      = entity.Password;
                        mUser.m_employee_id = entity.MEmployeeId;
                        mUser.m_role_id     = entity.MRoleId;
                        mUser.created_by    = "Admin";
                        mUser.created_date  = DateTime.Now;
                        mUser.is_delete     = false;
                        db.m_user.Add(mUser);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Success = false;
            }
            return(result);
        }
コード例 #25
0
        public static Responses Update(M_MenuViewModel entity)
        {
            Responses result = new Responses();

            try
            {
                using (var db = new MarcomContext())
                {
                    if (entity.Id != 0)
                    {
                        m_menu menu = db.m_menu.Where(m => m.id == entity.Id && m.id != entity.ParentId).FirstOrDefault();
                        if (menu != null)
                        {
                            menu.code         = entity.Code;
                            menu.name         = entity.Name;
                            menu.controller   = entity.Controller;
                            menu.parent_id    = entity.ParentId;
                            menu.is_delete    = entity.IsDelete;
                            menu.updated_by   = "Soleh";
                            menu.updated_date = DateTime.Now;
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        m_menu menu = new m_menu();
                        menu.code         = GetNewCode();
                        menu.name         = entity.Name;
                        menu.controller   = entity.Controller;
                        menu.parent_id    = entity.ParentId;
                        menu.is_delete    = false;
                        menu.created_by   = "Soleh";
                        menu.created_date = DateTime.Now;
                        db.m_menu.Add(menu);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Success = false;
            }
            return(result);
        }
コード例 #26
0
        //parent id
        public static List <M_MenuViewModel> GetByParentId(int PId)
        {
            List <M_MenuViewModel> result = new List <M_MenuViewModel>();

            using (var db = new MarcomContext())
            {
                result = (from m in db.m_menu
                          where m.id != PId && m.is_delete == false
                          select new M_MenuViewModel
                {
                    Id = m.id,
                    Code = m.code,
                    Name = m.name,
                    ParentId = m.parent_id
                }).ToList();
            }
            return(result);
        }
コード例 #27
0
        public static List <T_PromotionViewModel> Get()
        {
            List <T_PromotionViewModel> result = new List <T_PromotionViewModel>();

            using (var db = new MarcomContext())
            {
                result = (from p in db.t_promotion
                          join ev in db.t_event
                          on p.t_event_id equals ev.id
                          join e in db.m_employee
                          on p.request_by equals e.id
                          join em in db.m_employee
                          on p.assign_to equals em.id
                          where p.is_delete == false
                          select new T_PromotionViewModel
                {
                    Id = p.id,
                    Code = p.code,
                    FlagDesign = p.flag_design,
                    TEventId = p.t_event_id,
                    TEventCode = ev.code,
                    TDesignId = p.t_design_id,
                    RequestBy = p.request_by,
                    RFirstName = e.first_name,
                    RLastName = e.last_name,
                    RequestDate = p.request_date,
                    ApprovedBy = p.approved_by,
                    ApprovedDate = p.approved_date,
                    AssignTo = p.assign_to,
                    AFirstName = em.first_name,
                    ALastName = em.last_name,
                    CloseDate = p.close_date,
                    Note = p.note,
                    Status = p.status,
                    RejectReason = p.reject_reason,
                    IsDelete = p.is_delete,
                    CreatedBy = p.created_by,
                    CreatedDate = p.created_date,
                    UpdatedBy = p.updated_by,
                    UpdatedDate = p.updated_date,
                }).ToList();
            }
            return(result);
        }
コード例 #28
0
        public static Responses update(M_ProductViewModel entity)
        {
            Responses result = new Responses();

            try
            {
                using (var db = new MarcomContext())
                {
                    if (entity.Id != 0)
                    {
                        m_product m_product = db.m_product.Where(o => o.id == entity.Id).FirstOrDefault();
                        if (m_product != null)
                        {
                            m_product.code         = entity.Code;
                            m_product.name         = entity.Name;
                            m_product.description  = entity.Description;
                            m_product.is_delete    = entity.IsDelete;
                            m_product.updated_by   = "David";
                            m_product.updated_date = DateTime.Now;
                            db.SaveChanges();
                        }
                    }

                    else
                    {
                        m_product m_product = new m_product();
                        m_product.code         = entity.Code;
                        m_product.name         = entity.Name;
                        m_product.description  = entity.Description;
                        m_product.is_delete    = entity.IsDelete;
                        m_product.created_by   = entity.CreatedBy;
                        m_product.created_date = DateTime.Now;
                        db.m_product.Add(m_product);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Success = false;
            }
            return(result);
        }
コード例 #29
0
        public static Responses Update(M_RoleViewModel entity)
        {
            Responses result = new Responses();

            try
            {
                using (var db = new MarcomContext())
                {
                    if (entity.Id != 0)
                    {
                        m_role role = db.m_role.Where(o => o.id == entity.Id).FirstOrDefault();
                        if (role != null)
                        {
                            role.code         = entity.Code;
                            role.name         = entity.Name;
                            role.description  = entity.Description;
                            role.is_delete    = entity.IsDelete;
                            role.updated_by   = "Freeska";
                            role.updated_date = DateTime.Now;
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        m_role role = new m_role();
                        role.code         = entity.Code;
                        role.name         = entity.Name;
                        role.description  = entity.Description;
                        role.is_delete    = entity.IsDelete;
                        role.created_by   = "Freeska";
                        role.created_date = DateTime.Now;
                        db.m_role.Add(role);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Success = false;
            }
            return(result);
        }
コード例 #30
0
        public static List <M_UnitViewModel> Get()
        {
            List <M_UnitViewModel> result = new List <M_UnitViewModel>();

            using (var db = new MarcomContext())
            {
                result = (from u in db.m_unit
                          select new M_UnitViewModel
                {
                    Id = u.id,
                    Code = u.code,
                    Name = u.name,
                    Description = u.description,
                    CreatedDate = u.created_date,
                    CreatedBy = u.created_by,
                }).ToList();
            }
            return(result);
        }