public int CreateEditSalient(SalientFeature entity) { if (entity.ID == 0) { db.SalientFeatures.Add(entity); try { db.SaveChanges(); return(1); } catch (Exception) { throw; } } else if (entity.ID != 0) { var salient = db.SalientFeatures.Find(entity.ID); salient.Name = entity.Name; salient.Status = entity.Status; try { db.SaveChanges(); return(2); } catch (Exception) { throw; } } else { return(0); } }
public int CreateEditHomeCategory(Menu entity) { if (entity.ID == 0) { db.Menus.Add(entity); try { db.SaveChanges(); return(1); } catch (Exception) { return(0); } } if (entity.ID != 0) { Menu menu = db.Menus.Find(entity.ID); menu.Text = entity.Text; menu.Link = entity.Link; menu.DisplayOrder = entity.DisplayOrder; menu.Target = entity.Target; menu.Status = entity.Status; try { db.SaveChanges(); return(2); } catch (Exception) { return(0); } } return(0); }
public int CreateEditCarCategory(CarCategory entity, string username) { if (entity.ID == 0) { entity.CreatedBy = username; entity.ModifiedBy = username; entity.CreatedDate = DateTime.Now; entity.ModifiedDate = DateTime.Now; db.CarCategories.Add(entity); try { db.SaveChanges(); return(1); } catch (Exception) { return(0); } } if (entity.ID != 0) { CarCategory car = db.CarCategories.Find(entity.ID); car.Name = entity.Name; car.MetaTitle = entity.MetaTitle; car.ParentID = entity.ParentID; car.DisplayOrder = entity.DisplayOrder; car.SeoTitle = entity.SeoTitle; car.ModifiedBy = username; car.ModifiedDate = DateTime.Now; car.MetaKeywords = entity.MetaKeywords; car.MetaDescriptions = entity.MetaDescriptions; car.Status = entity.Status; if (car.ParentID != 0) { IEnumerable <CarCategory> listCar = db.CarCategories.Where(x => x.ParentID == entity.ID); int i = GetDisplayOrder(0, 0, "none") - 1; foreach (var item in listCar) { item.ParentID = 0; item.DisplayOrder = i++; } } try { db.SaveChanges(); return(2); } catch (Exception) { return(0); } } return(0); }
public int CreateEditCarPart(CarPart entity, string username) { if (entity.ID == 0) { entity.CreatedDate = DateTime.Now; entity.ModifiedDate = DateTime.Now; entity.CreatedBy = username; entity.ModifiedBy = username; db.CarParts.Add(entity); try { db.SaveChanges(); return(1); } catch (Exception) { throw; } } else if (entity.ID != 0) { var carpart = db.CarParts.Find(entity.ID); carpart.Name = entity.Name; carpart.Code = entity.Code; carpart.MetaTitle = entity.MetaTitle; carpart.SeoTitle = entity.SeoTitle; carpart.Description = entity.Description; carpart.Image = entity.Image; carpart.Price = entity.Price; carpart.PromotionPrice = entity.PromotionPrice; carpart.Quantity = entity.Quantity; carpart.CategoryID = entity.CategoryID; carpart.Warranty = entity.Warranty; carpart.OriginID = entity.OriginID; carpart.ManufacturerID = entity.ManufacturerID; carpart.ModifiedBy = username; carpart.ModifiedDate = DateTime.Now; carpart.MetaKeywords = entity.MetaKeywords; carpart.MetaDescriptions = entity.MetaDescriptions; carpart.Status = entity.Status; try { db.SaveChanges(); return(2); } catch (Exception) { throw; } } else { return(0); } }
public long InsertOrder(Order entity) { try { db.Orders.Add(entity); db.SaveChanges(); return(entity.ID); } catch (Exception) { return(entity.ID); } }
public int CreateEditContent(Content entity, string username) { if (entity.ID == 0) { entity.CreatedDate = DateTime.Now; entity.ModifiedDate = DateTime.Now; entity.CreatedBy = username == "" ? "admin" : username; entity.ModifiedBy = username == "" ? "admin" : username; entity.ViewCount = 0; db.Contents.Add(entity); try { db.SaveChanges(); return(1); } catch (Exception) { throw; } } else if (entity.ID != 0) { var content = db.Contents.Find(entity.ID); content.Name = entity.Name; content.Image = entity.Image; content.MetaTitle = entity.MetaTitle; content.CategoryID = entity.CategoryID; content.Detail = entity.Detail; content.ModifiedBy = username == "" ? "admin" : username; content.ModifiedDate = DateTime.Now; content.MetaKeywords = entity.MetaKeywords; content.MetaDescriptions = entity.MetaDescriptions; content.Status = entity.Status; content.Tags = entity.Tags; try { db.SaveChanges(); return(2); } catch (Exception) { throw; } } else { return(0); } }
public int CreateEditUser(User entity, string userName) { if (entity.ID == 0) { // id = 0 => user not exits => add entity.CreatedDate = DateTime.Now; entity.ModifiedDate = DateTime.Now; entity.CreatedBy = userName; entity.ModifiedBy = userName; entity.Status = true; db.Users.Add(entity); try { db.SaveChanges(); return(1); } catch (Exception) { throw; } } else if (entity.ID != 0) { // user != 0 => user exits in table => edit var user = db.Users.Find(entity.ID); user.Name = entity.Name; user.Address = entity.Address; user.Phone = entity.Phone; user.Email = entity.Email; user.ModifiedDate = entity.ModifiedDate; user.ModifiedBy = userName; user.GroupID = entity.GroupID; try { db.SaveChanges(); return(2); } catch (Exception) { throw; } } else { return(0); } }
public int CreateEditManufacturer(Manufacturer entity, string username) { if (entity.ID == 0) { entity.CreatedDate = DateTime.Now; entity.ModifiedDate = DateTime.Now; entity.CreatedBy = username; entity.ModifiedBy = username; db.Manufacturers.Add(entity); try { db.SaveChanges(); return(1); } catch (Exception) { throw; } } else if (entity.ID != 0) { var manufacturer = db.Manufacturers.Find(entity.ID); manufacturer.Name = entity.Name; manufacturer.ModifiedBy = username; manufacturer.ModifiedDate = DateTime.Now; manufacturer.Status = entity.Status; try { db.SaveChanges(); return(2); } catch (Exception) { throw; } } else { return(0); } }
public int CreateEditOrigin(Origin entity, string username) { if (entity.ID == 0) { entity.CreatedDate = DateTime.Now; entity.ModifiedDate = DateTime.Now; entity.CreatedBy = username; entity.ModifiedBy = username; db.Origins.Add(entity); try { db.SaveChanges(); return(1); } catch (Exception) { throw; } } else if (entity.ID != 0) { var origin = db.Origins.Find(entity.ID); origin.Name = entity.Name; origin.ModifiedBy = username; origin.ModifiedDate = DateTime.Now; origin.Status = entity.Status; try { db.SaveChanges(); return(2); } catch (Exception) { throw; } } else { return(0); } }
public bool InsertDetails(OrderDetail entity, long id) { entity.OrderID = id; try { db.OrderDetails.Add(entity); db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public int CreateEditMemberGroup(MemberGroup entity) { if (entity.ID == 0) { entity.DecenID = CreateNewDecen(); db.MemberGroups.Add(entity); try { db.SaveChanges(); return(1); } catch (Exception) { throw; } } else if (entity.ID != 0) { var memberGrp = db.MemberGroups.Find(entity.ID); memberGrp.Name = entity.Name; memberGrp.Description = entity.Description; try { db.SaveChanges(); return(2); } catch (Exception) { throw; } } else { return(0); } }
public bool InsertFeedBack(Feedback entity) { try { entity.CreatedDate = DateTime.Now; entity.Status = false; db.Feedbacks.Add(entity); db.SaveChanges(); return(true); } catch (Exception) { throw; } }
public int CreateEditCar(Car entity, string username) { if (entity.ID == 0) { entity.CreatedDate = DateTime.Now; entity.ModifiedDate = DateTime.Now; entity.CreatedBy = username; entity.ModifiedBy = username; db.Cars.Add(entity); try { db.SaveChanges(); return(1); } catch (Exception) { throw; } } else if (entity.ID != 0) { var car = db.Cars.Find(entity.ID); car.CategoryID = entity.CategoryID; car.Name = entity.Name; car.MetaTitle = entity.MetaTitle; car.SeoTitle = entity.SeoTitle; car.Image = entity.Image; car.Price = entity.Price; car.PrePay = entity.PrePay; car.Model = entity.Model; car.Engine = entity.Engine; car.Fuel = entity.Fuel; car.Gear = entity.Gear; car.KmTraveled = entity.KmTraveled; car.CarColor = entity.CarColor; car.InteriorColor = entity.InteriorColor; car.OriginID = entity.OriginID; car.YearOfManufacture = entity.YearOfManufacture; car.Seats = entity.Seats; car.DriveSystem = entity.DriveSystem; car.Doors = entity.Doors; car.SalientFeatures = entity.SalientFeatures; car.ModifiedBy = username; car.ModifiedDate = DateTime.Now; car.MetaKeywords = entity.MetaKeywords; car.MetaDescriptions = entity.MetaDescriptions; car.Sold = entity.Sold; car.Status = entity.Status; try { db.SaveChanges(); return(2); } catch (Exception) { throw; } } else { return(0); } }