public ResultStatus Edit(TOURIS_TM_SUB_CATEGORY subCategory) { try { TOURIS_TM_SUB_CATEGORY subCategoryNew = _ctx.TOURIS_TM_SUB_CATEGORY.Find(subCategory.ID); subCategoryNew.CATEGORY_ID = subCategory.CATEGORY_ID; subCategoryNew.VILLAGE_ID = subCategory.VILLAGE_ID; subCategoryNew.ADDRESS = subCategory.ADDRESS; subCategoryNew.SUB_CATEGORY_NAME = subCategory.SUB_CATEGORY_NAME; subCategoryNew.SUB_CATEGORY_DESCRIPTION = subCategory.SUB_CATEGORY_DESCRIPTION; subCategoryNew.START_TIME = subCategory.START_TIME; subCategoryNew.END_TIME = subCategory.END_TIME; subCategoryNew.PHOTO_PATH = subCategory.PHOTO_PATH; subCategoryNew.LAST_MODIFIED_TIME = subCategory.LAST_MODIFIED_TIME; subCategoryNew.LAST_MODIFIED_BY = subCategory.LAST_MODIFIED_BY; _ctx.Entry(subCategoryNew).State = System.Data.Entity.EntityState.Modified; _ctx.SaveChanges(); rs.SetSuccessStatus(); } catch (Exception ex) { rs.SetErrorStatus(ex.Message); } return(rs); }
public static void AuditEntities(this DbCtx db, IPrincipal principal) { try { var modifiedEntries = db.ChangeTracker.Entries() .Where(x => x.Entity is IHasAudit <string, DateTime?> && (x.State == EntityState.Added || x.State == EntityState.Modified)); var username = principal != null ? principal.Identity.Name : "anonymous"; var now = DateTime.UtcNow; foreach (var entry in modifiedEntries) { var entity = (IHasAudit <string, DateTime?>)entry.Entity; if (entry.State == EntityState.Added) { entity.CreatedAt = now; entity.Creator = username; } else { db.Entry(entity).Property(x => x.CreatedAt).IsModified = false; db.Entry(entity).Property(x => x.Creator).IsModified = false; } entity.ModifiedAt = now; entity.Modifier = username; } } catch (Exception ex) { } }
private async Task <List <SeasonEachConfViewModel> > GetParticipationViewModelsForEachConference() { List <Season> seasons = await _context.Seasons.ToListAsync(); List <SeasonEachConfViewModel> seasonEachConfViewModels = new List <SeasonEachConfViewModel>(); foreach (Season season in seasons) { List <Participation> participations = await _context.Participations.Where(p => p.Season.Equals(season)).ToListAsync(); List <PartEachConfViewModel> partEachConfViewModels = new List <PartEachConfViewModel>(); foreach (Participation part in participations) { await _context.Entry(part).Reference(p => p.User).LoadAsync(); partEachConfViewModels.Add(new PartEachConfViewModel { Id = part.Id, User = part.User.Degree + " " + part.User.FirstName + " " + part.User.LastName, ConfPart = part.ConferenceParticipation.GetValueOrDefault(), PaperPub = part.PaperPublication.GetValueOrDefault() }); } seasonEachConfViewModels.Add(new SeasonEachConfViewModel { Season = season.Name + " " + season.EditionNumber, Participations = partEachConfViewModels }); } return(seasonEachConfViewModels); }
public ResultStatus Edit(TOURIS_TM_SOSMED sosmed) { try { TOURIS_TM_SOSMED sosmedNew = _ctx.TOURIS_TM_SOSMED.Find(sosmed.ID); sosmedNew.TYPE = sosmed.TYPE; sosmedNew.NAME = sosmed.NAME; sosmedNew.DESCRIPTION = sosmed.DESCRIPTION; sosmedNew.ICON = sosmed.ICON; sosmedNew.URL = sosmed.URL; sosmedNew.DATA_EMBED = sosmed.DATA_EMBED; sosmedNew.HEIGHT = sosmed.HEIGHT; sosmedNew.WIDTH = sosmed.WIDTH; sosmedNew.DATA_WIDGET_ID = sosmed.DATA_WIDGET_ID; sosmedNew.LAST_MODIFIED_TIME = sosmed.LAST_MODIFIED_TIME; sosmedNew.LAST_MODIFIED_BY = sosmed.LAST_MODIFIED_BY; _ctx.Entry(sosmedNew).State = System.Data.Entity.EntityState.Modified; _ctx.SaveChanges(); rs.SetSuccessStatus(); } catch (Exception ex) { rs.SetErrorStatus(ex.Message); } return(rs); }
/// <summary> /// 设备的归还 /// </summary> /// <param name="equipmentId"></param> /// <returns> /// 0 : 指定Id的设备不存在 /// 1 : 操作成功 /// -1 : 指定设备未被领用 /// </returns> public int ReturnEquipment(int equipmentId, string adminAccount) { var equipment = DbCtx.Equipments .FirstOrDefault(e => e.Id == equipmentId); if (equipment == null) { return(0); } if (equipment.User == null) { return(-1); } DbCtx.Histories.Add(new History() { ReturnDate = DateTime.Now, EquipmentTitle = equipment.Title, UserName = equipment.User.Name, AdminAccount = adminAccount }); //添加归还记录 equipment.User = null; //删除当前领用用户 DbCtx.Entry(equipment).State = EntityState.Modified; DbCtx.SaveChanges(); return(1); }
public ActionResult Edit([Bind(Include = "RecenzieId,Titlu,Descriere,Nota,NumeUtilizator")] Recenzie recenzie) { if (ModelState.IsValid) { db.Entry(recenzie).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(recenzie)); }
public ActionResult Edit([Bind(Include = "IDRecenzie,Titlu,Nota,IDFilm")] Recenzie recenzie) { if (ModelState.IsValid) { db.Entry(recenzie).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(recenzie)); }
public void Update(ContactModel dBcontact, ContactModel contact) { Contact dBentity = Contact.formModel(dBcontact); Contact entity = Contact.formModel(contact); _ctx.Entry(dBentity).CurrentValues.SetValues(entity); _ctx.Entry(dBentity.Address).CurrentValues.SetValues(entity.Address); // Delete Contracts foreach (var child in dBentity.Contracts.ToList()) { if (!entity.Contracts.Any(c => c.ContactId == child.ContactId && c.EntrepriseId == child.EntrepriseId)) { _ctx.Contract.Remove(child); } } //update or insert foreach (var child in entity.Contracts) { var existingChild = dBentity.Contracts .Where(c => c.ContactId == child.ContactId && c.EntrepriseId == child.EntrepriseId) .SingleOrDefault(); if (existingChild != null) { // Update child _ctx.Entry(existingChild).CurrentValues.SetValues(child); } else { // Insert child var newChild = new Contract { ContractType = child.ContractType, TVA = child.TVA, EntrepriseId = child.EntrepriseId }; dBentity.Contracts.Add(newChild); } } _ctx.SaveChanges(); }
public ActionResult Edit([Bind(Include = "Id,CurrentlyBooked,CurrentCustomerId,RoomSize,PricePerNight")] Room room) { if (ModelState.IsValid) { db.Entry(room).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(room)); }
public ActionResult Edit([Bind(Include = "Id,FirstName,LastName,Salary")] Employee employee) { if (ModelState.IsValid) { db.Entry(employee).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(employee)); }
public ActionResult Edit([Bind(Include = "Id,RoomId,StartDate,EndDate,CustomerId")] Reservation reservation) { if (ModelState.IsValid) { db.Entry(reservation).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.RoomId = new SelectList(db.Rooms, "Id", "Id", reservation.RoomId); return(View(reservation)); }
public ResultStatus Delete(int id, string modifiedBy, DateTime modifiedTime) { try { GEMA_TM_USER user = _ctx.GEMA_TM_USER.Find(id); user.LAST_MODIFIED_TIME = modifiedTime; user.LAST_MODIFIED_BY = modifiedBy; user.ROW_STATUS = eStat.fg.NotActive; _ctx.Entry(user).State = EntityState.Modified; _ctx.SaveChanges(); rs.SetSuccessStatus(); } catch (Exception ex) { rs.SetErrorStatus(ex.Message); } return(rs); }
public ResultStatus Edit(TOURIS_TM_ROLE role) { try { TOURIS_TM_ROLE roleNew = _ctx.TOURIS_TM_ROLE.Find(role.ID); roleNew.ROLE_NAME = role.ROLE_NAME; roleNew.ROLE_DESCRIPTION = role.ROLE_DESCRIPTION; roleNew.LAST_MODIFIED_TIME = role.LAST_MODIFIED_TIME; roleNew.LAST_MODIFIED_BY = role.LAST_MODIFIED_BY; _ctx.Entry(roleNew).State = System.Data.Entity.EntityState.Modified; _ctx.SaveChanges(); rs.SetSuccessStatus(); } catch (Exception ex) { rs.SetErrorStatus(ex.Message); } return(rs); }
public ActionResult Edit([Bind(Include = "Id,Title,RoomId,EmployeeId")] Job job) { if (ModelState.IsValid) { db.Entry(job).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.EmployeeId = new SelectList(db.Employees, "Id", "FirstName", job.EmployeeId); ViewBag.RoomId = new SelectList(db.Rooms, "Id", "Id", job.RoomId); return(View(job)); }
public ResultStatus Edit(TOURIS_TM_MENU menu) { try { TOURIS_TM_MENU menuNew = _ctx.TOURIS_TM_MENU.Find(menu.ID); menuNew.MENU_NAME = menu.MENU_NAME; menuNew.MENU_DESCRIPTION = menu.MENU_DESCRIPTION; menuNew.MENU_PARENT_ID = menu.MENU_PARENT_ID; menuNew.LAST_MODIFIED_TIME = menu.LAST_MODIFIED_TIME; menuNew.LAST_MODIFIED_BY = menu.LAST_MODIFIED_BY; _ctx.Entry(menuNew).State = System.Data.Entity.EntityState.Modified; _ctx.SaveChanges(); rs.SetSuccessStatus(); } catch (Exception ex) { rs.SetErrorStatus(ex.Message); } return(rs); }
public ResultStatus Edit(TOURIS_TM_COUNTRY country) { try { TOURIS_TM_COUNTRY countryNew = _ctx.TOURIS_TM_COUNTRY.Find(country.ID); countryNew.COUNTRY_CODE = country.COUNTRY_CODE; countryNew.COUNTRY_NAME = country.COUNTRY_NAME; countryNew.COUNTRY_DESCRIPTION = country.COUNTRY_DESCRIPTION; countryNew.LAST_MODIFIED_TIME = country.LAST_MODIFIED_TIME; countryNew.LAST_MODIFIED_BY = country.LAST_MODIFIED_BY; _ctx.Entry(countryNew).State = System.Data.Entity.EntityState.Modified; _ctx.SaveChanges(); rs.SetSuccessStatus(); } catch (Exception ex) { rs.SetErrorStatus(ex.Message); } return(rs); }
public ResultStatus Edit(TOURIS_TM_VILLAGE village) { try { TOURIS_TM_VILLAGE villageNew = _ctx.TOURIS_TM_VILLAGE.Find(village.ID); villageNew.DISTRICT_ID = village.DISTRICT_ID; villageNew.VILLAGE_CODE = village.VILLAGE_CODE; villageNew.VILLAGE_NAME = village.VILLAGE_NAME; villageNew.VILLAGE_DESCRIPTION = village.VILLAGE_DESCRIPTION; villageNew.LAST_MODIFIED_TIME = village.LAST_MODIFIED_TIME; villageNew.LAST_MODIFIED_BY = village.LAST_MODIFIED_BY; _ctx.Entry(villageNew).State = System.Data.Entity.EntityState.Modified; _ctx.SaveChanges(); rs.SetSuccessStatus(); } catch (Exception ex) { rs.SetErrorStatus(ex.Message); } return(rs); }
public ResultStatus Edit(TOURIS_TM_DISTRICT district) { try { TOURIS_TM_DISTRICT districtNew = _ctx.TOURIS_TM_DISTRICT.Find(district.ID); districtNew.CITY_ID = district.CITY_ID; districtNew.DISTRICT_CODE = district.DISTRICT_CODE; districtNew.DISTRICT_NAME = district.DISTRICT_NAME; districtNew.DISTRICT_DESCRIPTION = district.DISTRICT_DESCRIPTION; districtNew.LAST_MODIFIED_TIME = district.LAST_MODIFIED_TIME; districtNew.LAST_MODIFIED_BY = district.LAST_MODIFIED_BY; _ctx.Entry(districtNew).State = System.Data.Entity.EntityState.Modified; _ctx.SaveChanges(); rs.SetSuccessStatus(); } catch (Exception ex) { rs.SetErrorStatus(ex.Message); } return(rs); }
public ResultStatus Edit(TOURIS_TM_CONTACT_US contactUs) { try { TOURIS_TM_CONTACT_US contactUsNew = _ctx.TOURIS_TM_CONTACT_US.Find(contactUs.ID); contactUsNew.NAME_SENDER = contactUs.NAME_SENDER; contactUsNew.EMAIL_SENDER = contactUs.EMAIL_SENDER; contactUsNew.PHONE_SENDER = contactUs.EMAIL_SENDER; contactUsNew.DESCRIPTION = contactUs.DESCRIPTION; contactUsNew.LAST_MODIFIED_TIME = contactUs.LAST_MODIFIED_TIME; contactUsNew.LAST_MODIFIED_BY = contactUs.LAST_MODIFIED_BY; _ctx.Entry(contactUsNew).State = System.Data.Entity.EntityState.Modified; _ctx.SaveChanges(); rs.SetSuccessStatus(); } catch (Exception ex) { rs.SetErrorStatus(ex.Message); } return(rs); }
public ResultStatus Edit(TOURIS_TM_SUB_CATEGORY_PHOTO subCategoryPhoto) { try { TOURIS_TM_SUB_CATEGORY_PHOTO subCategoryPhotoNew = _ctx.TOURIS_TM_SUB_CATEGORY_PHOTO.Find(subCategoryPhoto.ID); subCategoryPhotoNew.SUB_CATEGORY_ID = subCategoryPhoto.SUB_CATEGORY_ID; subCategoryPhotoNew.PHOTO_NAME = subCategoryPhoto.PHOTO_NAME; subCategoryPhotoNew.PHOTO_DESCRIPTION = subCategoryPhoto.PHOTO_DESCRIPTION; subCategoryPhotoNew.PHOTO_PATH = subCategoryPhoto.PHOTO_PATH; subCategoryPhotoNew.LAST_MODIFIED_TIME = subCategoryPhoto.LAST_MODIFIED_TIME; subCategoryPhotoNew.LAST_MODIFIED_BY = subCategoryPhoto.LAST_MODIFIED_BY; _ctx.Entry(subCategoryPhotoNew).State = System.Data.Entity.EntityState.Modified; _ctx.SaveChanges(); rs.SetSuccessStatus(); } catch (Exception ex) { rs.SetErrorStatus(ex.Message); } return(rs); }
/// <summary> /// 删除一个设备 /// </summary> /// <param name="Id">设备的Id</param> /// <returns> /// 0 : 对应Id的设备不存在 /// 1 : 操作成功 /// </returns> public int DeleteEquipment(int Id) { var equipment = DbCtx.Equipments .FirstOrDefault(e => e.Id == Id); if (equipment == null) //此Id不存在 { return(0); //返回0 } DbCtx.Entry(equipment).State = EntityState.Deleted; DbCtx.SaveChanges(); return(1); }
public ResultStatus Edit(GEMA_TM_SUB_CATEGORY subCategory) { try { GEMA_TM_SUB_CATEGORY subCategoryNew = _ctx.GEMA_TM_SUB_CATEGORY.Find(subCategory.ID); subCategoryNew.CATEGORY_ID = subCategory.CATEGORY_ID; subCategoryNew.SUB_CATEGORY_NAME = subCategory.SUB_CATEGORY_NAME; subCategoryNew.DESCRIPTION = subCategory.DESCRIPTION; subCategoryNew.IMAGE_PATH = subCategory.IMAGE_PATH; subCategoryNew.LAST_MODIFIED_TIME = subCategory.LAST_MODIFIED_TIME; subCategoryNew.LAST_MODIFIED_BY = subCategory.LAST_MODIFIED_BY; _ctx.Entry(subCategoryNew).State = System.Data.Entity.EntityState.Modified; _ctx.SaveChanges(); rs.SetSuccessStatus(); } catch (Exception ex) { rs.SetErrorStatus(ex.Message); } return(rs); }
public ResultStatus Edit(TOURIS_TM_PROVINCE province) { try { TOURIS_TM_PROVINCE provinceNew = _ctx.TOURIS_TM_PROVINCE.Find(province.ID); provinceNew.COUNTRY_ID = province.COUNTRY_ID; provinceNew.PROVINCE_CODE = province.PROVINCE_CODE; provinceNew.PROVINCE_NAME = province.PROVINCE_NAME; provinceNew.PROVINCE_DESCRIPTION = province.PROVINCE_DESCRIPTION; provinceNew.LAST_MODIFIED_TIME = province.LAST_MODIFIED_TIME; provinceNew.LAST_MODIFIED_BY = province.LAST_MODIFIED_BY; _ctx.Entry(provinceNew).State = System.Data.Entity.EntityState.Modified; _ctx.SaveChanges(); rs.SetSuccessStatus(); } catch (Exception ex) { rs.SetErrorStatus(ex.Message); } return(rs); }
public ResultStatus Edit(GEMA_TR_BOOKING booking) { using (var transaction = _ctx.Database.BeginTransaction()) { try { GEMA_TR_BOOKING bookingNew = _ctx.GEMA_TR_BOOKING.Find(booking.ID); if (booking.STATUS == (int)EnumList.BookingStatus.Submitted) { bookingNew.STATUS = (int)EnumList.BookingStatus.Uploaded; bookingNew.RECEIVE_PAYMENT_BY = booking.LAST_MODIFIED_BY; bookingNew.RECEIVE_PAYMENT_TIME = booking.LAST_MODIFIED_TIME; bookingNew.PAYMENT_IMAGE_PATH = booking.PAYMENT_IMAGE_PATH; } else if (booking.STATUS == (int)EnumList.BookingStatus.Uploaded) { bookingNew.STATUS = (int)EnumList.BookingStatus.Completed; bookingNew.COMPLETE_PAYMENT_BY = booking.LAST_MODIFIED_BY; bookingNew.COMPLETE_PAYMENT_TIME = booking.LAST_MODIFIED_TIME; } bookingNew.LAST_MODIFIED_TIME = booking.LAST_MODIFIED_TIME; bookingNew.LAST_MODIFIED_BY = booking.LAST_MODIFIED_BY; _ctx.Entry(bookingNew).State = System.Data.Entity.EntityState.Modified; _ctx.SaveChanges(); rs.SetSuccessStatus(); transaction.Commit(); } catch (Exception ex) { rs.SetErrorStatus(ex.Message); transaction.Rollback(); } } return(rs); }
public ResultStatus Edit(GEMA_TM_PRICEL_LIST priceList) { try { GEMA_TM_PRICEL_LIST priceListNew = _ctx.GEMA_TM_PRICEL_LIST.Find(priceList.ID); priceListNew.TYPE = priceList.TYPE; priceListNew.DESCRIPTION = priceList.DESCRIPTION; priceListNew.PRICE = priceList.PRICE; priceListNew.IMAGE_BIT = priceList.IMAGE_BIT; priceListNew.IMAGE_PATH = priceList.IMAGE_PATH; priceListNew.LAST_MODIFIED_TIME = priceList.LAST_MODIFIED_TIME; priceListNew.LAST_MODIFIED_BY = priceList.LAST_MODIFIED_BY; _ctx.Entry(priceListNew).State = System.Data.Entity.EntityState.Modified; _ctx.SaveChanges(); rs.SetSuccessStatus(); } catch (Exception ex) { rs.SetErrorStatus(ex.Message); } return(rs); }
public ResultStatus Edit(GEMA_TM_SLIDESHOW slideshow) { try { GEMA_TM_SLIDESHOW slideshowNew = _ctx.GEMA_TM_SLIDESHOW.Find(slideshow.ID); slideshowNew.TITTLE = slideshow.TITTLE; slideshowNew.CONTENT_DESCRIPTION = slideshow.CONTENT_DESCRIPTION; slideshowNew.CLASS = slideshow.CLASS; slideshowNew.PHOTO_PATH = slideshow.PHOTO_PATH; slideshowNew.URL = slideshow.URL; slideshowNew.LAST_MODIFIED_TIME = slideshow.LAST_MODIFIED_TIME; slideshowNew.LAST_MODIFIED_BY = slideshow.LAST_MODIFIED_BY; _ctx.Entry(slideshowNew).State = System.Data.Entity.EntityState.Modified; _ctx.SaveChanges(); rs.SetSuccessStatus(); } catch (Exception ex) { rs.SetErrorStatus(ex.Message); } return(rs); }
public ResultStatus Edit(GEMA_TM_CATEGORY category) { try { GEMA_TM_CATEGORY categoryNew = _ctx.GEMA_TM_CATEGORY.Find(category.ID); categoryNew.CATEGORY_NAME = category.CATEGORY_NAME; categoryNew.DESCRIPTION = category.DESCRIPTION; categoryNew.URL = category.URL; categoryNew.CLASS = category.CLASS; categoryNew.IMAGE_PATH = category.IMAGE_PATH; categoryNew.LAST_MODIFIED_TIME = category.LAST_MODIFIED_TIME; categoryNew.LAST_MODIFIED_BY = category.LAST_MODIFIED_BY; _ctx.Entry(categoryNew).State = System.Data.Entity.EntityState.Modified; _ctx.SaveChanges(); rs.SetSuccessStatus(); } catch (Exception ex) { rs.SetErrorStatus(ex.Message); } return(rs); }
/// <summary> /// 删除一个设备类别 /// </summary> /// <param name="Id"></param> /// <returns> /// -2 : 指定Id的设备小类下面有设备 /// -1 : 指定Id的设备种类不存在 /// 0 : 指定Id的设备大类下有小类 /// 1 : 删除成功 /// </returns> public int DeleteEquipmentType(int id) { var equipmentType = DbCtx.EquipmentTypes .FirstOrDefault(et => et.Id == id); if (equipmentType == null) { return(-1); } if (equipmentType.Type == 0) { IList <EquipmentType> equipmentTypes = DbCtx.EquipmentTypes .Where(et => et.BigEquipmentType.Id == equipmentType.Id) .ToList(); //查找当前大类下面是否有小类 if (equipmentTypes.Count != 0) { return(0); } } else if (equipmentType.Type == 1) { IList <Equipment> equipments = DbCtx.Equipments .Where(e => e.EquipmentType.Id == equipmentType.Id) .ToList(); //查找当前小类下面是否有设备 if (equipments.Count != 0) { return(-2); } } else { throw new MyException("应该只有大类和小类,请检查数据库", 6); } DbCtx.Entry(equipmentType).State = EntityState.Deleted; DbCtx.SaveChanges(); return(1); }
/// <summary> /// 领用某一设备 /// </summary> /// <param name="userId">要领用设备的用户Id</param> /// <param name="equipmentId">被领用设备的Id</param> /// <returns> /// 1 : 操作成功 /// 0 : 没有对应的user或者没有对应的设备 /// -1 : 设备已经被占用 /// -2 : 设备在维修或已经报废 /// </returns> public int BorrowEquipment(int userId, int equipmentId) { var user = DbCtx.Users .FirstOrDefault(u => u.Id == userId); //得到用户 var equipment = DbCtx.Equipments .FirstOrDefault(e => e.Id == equipmentId); //得到设备 if (user == null || equipment == null) { return(0); } if (equipment.User != null) //设备被占用 { return(-1); } if (equipment.State != 0) //设备在维修或者报废 { return(-2); } equipment.User = user; //修改用户为指定用户 DbCtx.Entry(equipment).State = EntityState.Modified; DbCtx.SaveChanges(); return(1); }
public void Update(T entity) { ctx.Entry(entity).State = EntityState.Modified; ctx.SaveChanges(); }