public ServiceResponse <m_company> EditCompany(m_company company) { try { _ctx.m_companies.Update(company); _ctx.SaveChanges(); return(new ServiceResponse <m_company> { IsSuccess = true, Time = DateTime.UtcNow, Message = "Company Updated", Data = company }); } catch (Exception e) { return(new ServiceResponse <m_company> { IsSuccess = false, Time = DateTime.UtcNow, Message = e.StackTrace, Data = null }); } }
public ServiceResponse <m_company> CreateCompany(m_company company) { try { company.Code = "CP" + GenerateCode(); company.IsDelete = false; company.CreatedBy = ""; company.CreatedDate = DateTime.UtcNow; _ctx.m_companies.Add(company); _ctx.SaveChanges(); return(new ServiceResponse <m_company> { IsSuccess = true, Time = DateTime.UtcNow, Message = "Company Created", Data = company }); } catch (Exception e) { return(new ServiceResponse <m_company> { IsSuccess = false, Time = DateTime.UtcNow, Message = e.StackTrace, Data = null }); } }
public static bool Delete(MCompanyVM model) { bool result = false; using (AppEntity db = new AppEntity()) { m_company item = db.m_company.Find(model.id); item.is_active = false; item.updated_by = 1; item.updated_date = DateTime.Now; try { db.SaveChanges(); result = true; } catch (Exception) { throw; } } return(result); }
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); }
public static companyViewModel SerializeCompany(m_company company) { return(new companyViewModel { Id = company.Id, Code = company.Code, Name = company.Name, Address = company.Address, Phone = company.Phone, Email = company.Email, IsDelete = company.IsDelete, CreatedBy = company.CreatedBy, CreatedDate = company.CreatedDate, UpdatedBy = company.UpdatedBy, UpdatedDate = company.UpdatedDate }); }
public static bool update(MCompanyVM model) { bool result = false; using (AppEntity db = new AppEntity()) { m_company item = db.m_company.Find(model.id); item.id = model.id; item.code = model.code; item.name = model.name; item.address = model.address; item.phone = model.phone; item.is_active = true; item.email = model.email; item.updated_by = 1; item.updated_date = DateTime.Now; try { db.SaveChanges(); result = true; } catch (Exception) { throw; } } return(result); }
public static bool insert(MCompanyVM model) { bool result = false; using (AppEntity db = new AppEntity()) { m_company item = new m_company() { code = model.code, name = model.name, address = model.address, phone = model.phone, email = model.email, is_active = true, created_by = 1, created_date = DateTime.Now }; db.m_company.Add(item); try { db.SaveChanges(); result = true; } catch (Exception) { throw; } } return(result); }
public static string CreateCompany(CompanyViewModel paramDataCompany) { string latestSaveCode = string.Empty; using (var db = new MarkomApplicationDBEntities()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { m_company c = new m_company(); c.code = CompanyCode(); c.name = paramDataCompany.name; c.address = paramDataCompany.address; c.phone = paramDataCompany.phone; c.email = paramDataCompany.email; c.is_delete = paramDataCompany.isDelete; c.create_by = paramDataCompany.createBy; c.create_date = paramDataCompany.createDate; db.m_company.Add(c); db.SaveChanges(); dbContextTransaction.Commit(); //get latest save code latestSaveCode = c.code; } catch (Exception ex) { Message = ex.Message; dbContextTransaction.Rollback(); //throw; } } } return(latestSaveCode); }
public static Responses Delete(int id) { Responses result = new Responses(); try { using (var db = new MarcomContext()) { m_company company = db.m_company.Where(o => o.id == id).FirstOrDefault(); if (company != null) { company.is_delete = true; db.SaveChanges(); } } } catch (Exception ex) { result.Message = ex.Message; result.Success = false; } return(result); }