Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public static bool Delete(int id)
        {
            bool res = false;

            using (AppEntity db = new AppEntity())
            {
                m_souvenir data = db.m_souvenir.Find(id);
                data.id           = data.id;
                data.code         = data.code;
                data.name         = data.name;
                data.is_active    = false;
                data.updated_by   = 1;
                data.updated_date = DateTime.Now;

                try { db.SaveChanges(); res = true; } catch (Exception) { throw; }
            }
            return(res);
        }
Exemplo n.º 3
0
        public static bool Update(MSouvenirVM model)
        {
            bool res = false;

            using (AppEntity db = new AppEntity())
            {
                m_souvenir data = db.m_souvenir.Find(model.id);
                data.code         = model.code;
                data.name         = model.name;
                data.description  = model.description;
                data.m_unit_id    = model.m_unit_id;
                data.updated_by   = 1;
                data.updated_date = DateTime.Now;

                try { db.SaveChanges(); res = true; } catch (Exception) { throw; }
            }
            return(res);
        }
Exemplo n.º 4
0
        public static bool Insert(MSouvenirVM model)
        {
            bool res = false;

            using (AppEntity db = new AppEntity())
            {
                m_souvenir data = new m_souvenir()
                {
                    code         = model.code,
                    name         = model.name,
                    description  = model.description,
                    m_unit_id    = model.m_unit_id,
                    created_by   = 1,
                    created_date = DateTime.Now,
                    is_active    = true
                };

                db.m_souvenir.Add(data);
                try { db.SaveChanges(); res = true; } catch (Exception) { throw; }
            }
            return(res);
        }
Exemplo n.º 5
0
        public static Responses Delete(int id)
        {
            Responses result = new Responses();

            try
            {
                using (var db = new MarcomContext())
                {
                    m_souvenir souvenir = db.m_souvenir.Where(o => o.id == id).FirstOrDefault();
                    if (souvenir != null)
                    {
                        souvenir.is_delete = true;
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Success = false;
            }
            return(result);
        }
Exemplo n.º 6
0
        public static string CreateSouvenir(SouvenirViewModel paramDataSou)
        {
            string latestSaveCode = string.Empty;

            using (var db = new MarkomApplicationDBEntities())
            {
                using (var dbContextTransaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        m_souvenir c = new m_souvenir();
                        c.code        = SouvenirCode();
                        c.name        = paramDataSou.name;
                        c.m_unit_id   = paramDataSou.mUnitId;
                        c.description = paramDataSou.description;
                        c.is_delete   = paramDataSou.isDelete;
                        c.create_by   = paramDataSou.createBy;
                        c.create_date = paramDataSou.createDate;

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

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

            return(latestSaveCode);
        }