public async Task ExampleUseUnitOfWork() { using (var unitOfWork = manager.Create()) { var entity = new UserEntity { Id = 1, Date = DateTime.Now, Name = "test" }; repository.AddOrUpdate(entity); using (var nestedUnitOfWork = manager.Create()) { var entity2 = new UserEntity { Id = 2, Date = DateTime.Now, Name = "test2" }; repository.AddOrUpdate(entity2); await nestedUnitOfWork.SaveChangesAsync(); } foreach (var u in repository.DataSet) { Console.WriteLine("should be for id == 2"); Console.WriteLine(u.Id); Console.WriteLine(u.Name); Console.WriteLine(u.Date); Console.WriteLine("should not see anymore till done"); } await unitOfWork.SaveChangesAsync(); } }
public ActionResult EditEmployee(int EmpId, string First_Name, string Last_Name, string Patronimyc, int Department_Id, int Speciality_Id, int Position_id, string Phone, string Email, DateTime?BirthDay, string Gender, string Hobby ) { Employee emp; emp = EmployeeRep.Get((int)EmpId); emp.last_name = Last_Name; emp.first_name = First_Name; emp.patronimyc = Patronimyc; emp.emp_department_id = Department_Id; emp.emp_speciality_id = Speciality_Id; emp.emp_position_id = Position_id; emp.phone_mobile = Phone; emp.email = Email; emp.edited_by = User.Identity.Name; emp.edited_date = DateTime.UtcNow; emp.birthday = BirthDay; emp.gender = Gender; emp.hobby = Hobby; EmployeeRep.AddOrUpdate(emp); return(new EmptyResult()); }
public StreetDTO Add(StreetDTO obj) { Street street = _mapper.Map <Street>(obj); streetRepository.AddOrUpdate(street); streetRepository.Save(); return(_mapper.Map <StreetDTO>(street)); }
public GoodDTO Add(GoodDTO obj) { Good good = _mapper.Map <Good>(obj); goodRepository.AddOrUpdate(good); goodRepository.Save(); return(_mapper.Map <GoodDTO>(good)); }
public D Add(D obj) { T elem = _mapper.Map <T>(obj); repository.AddOrUpdate(elem); repository.Save(); return(_mapper.Map <D>(elem)); }
public DTO Add(DTO obj) { DOMAIN address = mapper.Map <DOMAIN>(obj); repository.AddOrUpdate(address); repository.Save(); return(mapper.Map <DTO>(address)); }
public SubdivisionDTO Add(SubdivisionDTO obj) { Subdivision subdivision = _mapper.Map <Subdivision>(obj); subdvsRepository.AddOrUpdate(subdivision); subdvsRepository.Save(); return(_mapper.Map <SubdivisionDTO>(subdivision)); }
public ManufacturerDTO Add(ManufacturerDTO obj) { Manufacturer manufacturer = _mapper.Map <Manufacturer>(obj); manufacturerRepository.AddOrUpdate(manufacturer); manufacturerRepository.Save(); return(_mapper.Map <ManufacturerDTO>(manufacturer)); }
public AddressDTO Add(AddressDTO obj) { Address address = _mapper.Map <Address>(obj); addressRepository.AddOrUpdate(address); addressRepository.Save(); return(_mapper.Map <AddressDTO>(address)); }
public ActionResult IdentityUsers(IdentityUser obj) { if (ModelState.IsValid) { IdentityUserRep.AddOrUpdate(obj); } return(RedirectToAction("IdentityUsers")); }
public HttpResponseMessage Post([FromBody] Manufacturer value) { repository.AddOrUpdate(value); var message = Request.CreateResponse(HttpStatusCode.Created, value); string url = Url.Link("ManufacturerApi", new { id = value.ManufacturerId }); message.Headers.Location = new Uri(url); return(message); }
public ActionResult Institutions(Institution obj) { if (ModelState.IsValid) { InstitutionRep.AddOrUpdate(obj); return(RedirectToAction("Institutions")); } return(RedirectToAction("Institutions")); }
public ActionResult Prescriptions() { var model = new PrescDynamicsListViewModel(); int MyId = Convert.ToInt32(User.Identity.GetUserId()); List <Region> regions; var MyCountryCode = RegionRep.Get((int)CUserRep.FindBy(i => i.id == MyId).FirstOrDefault().base_region_id).country_code; if (User.IsInRole("admin") || User.IsInRole("DD")) { regions = RegionRep.FindBy(i => (bool)i.is_actual == true).OrderBy(k => k.name).ToList(); } if (User.IsInRole("seeAllUsers")) { regions = RegionRep.FindBy(i => (bool)i.is_actual == true && i.country_code.Equals(MyCountryCode)).OrderBy(k => k.name).ToList(); } else { regions = AssignedRegionsRep.FindBy(i => i.cuser_id == MyId).GroupBy(i => new { i.region_id, i.Region.name }) .Select(i => new Region { id = (int)i.First().region_id, name = i.First().Region.name }).OrderBy(p => p.name).ToList(); } model.region_id = regions.First().id; ViewBag.RegionList = new SelectList(regions, "id", "name", model.region_id); List <Report_> modes = new List <Report_>(); modes.Add(new Report_() { id = 0, name = "уп. / грн." }); modes.Add(new Report_() { id = 1, name = "уп." }); modes.Add(new Report_() { id = 2, name = "грн." }); ViewBag.ChooseMode = new SelectList(modes, "id", "name", model.mode_id); model.year_ = DateTime.Now.Year; Journal record = new Journal() { operation_name = "Просмотр отчета Динамика назначений", cuser_name = User.Identity.GetUserName(), edited_date = DateTime.Now }; JournalRep.AddOrUpdate(record); return(View(model)); }
public TDTO Add(TDTO obj) { try { T address = _mapper.Map <T>(obj); repository.AddOrUpdate(address); repository.Save(); return(_mapper.Map <TDTO>(address)); } catch (Exception e) { throw e; } }
public ActionResult NewMessage(IEnumerable <string> values, string mes_text, int?parent_id, int?prev_mes_id) { int par_id; if (parent_id == null) { par_id = 0; } else { par_id = (int)parent_id; } if (prev_mes_id != null) { var prev_mes = MessageAddressingRep.Get((int)prev_mes_id); prev_mes.message_status = 1; MessageAddressingRep.AddOrUpdate(prev_mes); } var guid = Guid.NewGuid().ToString(); Messaging message = new Messaging() { message_type_id = 1, message_text = mes_text, message_status = 0, parent_id = par_id, user_from_id = MyId, stamp = guid, message_date = DateTime.Now }; MessagingRep.AddOrUpdate(message); message = MessagingRep.FindBy(i => i.stamp.Equals(guid)).First(); if (message != null) { message.parent_id = message.id; MessagingRep.AddOrUpdate(message); if (values != null) { foreach (var item in values) { var newReceiver = new MessageAddressing() { messaging_id = message.id, cuser_receiver = Convert.ToInt32(item), message_status = 0 }; MessageAddressingRep.AddOrUpdate(newReceiver); } } } return(View()); }
public ActionResult AddActivity( int Call_template_Id, int Emp_Id, int Cuser_Id, int Act_state_detalization_Id, int Act_state_Id, int Act_type_Id, string UID ) { Activity Act = new Activity() { plan_date = DateTime.Now, fact_date = DateTime.Now, created_date = DateTime.UtcNow, edited_date = DateTime.UtcNow, act_state_detalization_id = Act_state_detalization_Id, act_state_id = Act_state_Id, cuser_id = Cuser_Id, emp_id = Emp_Id, call_template_id = Call_template_Id, act_type_id = Act_type_Id, created_by = User.Identity.Name, edited_by = User.Identity.Name, goal_planned = UID }; ActivityRep.AddOrUpdate(Act); return(new EmptyResult()); }
public ActionResult FinishVisit(int ActId, string resume, IEnumerable <string> products, bool?double_visit) { var act = ActivityRep.Get(ActId); act.act_state_id = 2; act.fact_date = act.plan_date; act.goal_achieved = resume; act.double_visit = double_visit; act.edited_date = DateTime.UtcNow; act.edited_by = User.Identity.Name; ActivityRep.AddOrUpdate(act); if (products != null) { foreach (var item in products) { var ActivityProd = new ActivityProduct() { prod_id = Convert.ToInt32(item), act_id = act.id }; ActivityProductRep.AddOrUpdate(ActivityProd); } } return(new EmptyResult()); }
public BizEmployee AddOrUpdate(BizEmployee obj) { Employee emp = mapper.Map <Employee>(obj); employeeRep.AddOrUpdate(emp); return(mapper.Map <BizEmployee>(emp)); }
public IHttpActionResult UpdatePushNotificationToken(string fcmToken) { if (!Guid.TryParse(User.Identity.GetUserId(), out var userId)) { return(Unauthorized()); } string accessToken = GetAccessToken(); using (unitOfWorkFactory.Create()) { var token = tokenRepository .Get(t => t.UserId == userId && t.AccessToken == accessToken) .SingleOrDefault() ?? new NotificationToken { AccessToken = accessToken, Token = fcmToken, UserId = userId }; tokenRepository.AddOrUpdate(token, t => t.Id); } return(Ok()); }
public ActionResult DeleteAssignment(int AssignmentId) { try { InstAssignment a = InstAssignmentRep.Get(AssignmentId); Journal journal_record = new Journal() { operation_name = "удаление закрепления пользователя за ЛПУ", text_old = a.IdentityUser.LastName + " / " + a.Institution.name, table_name = "InstAssignment", record_id_in_table = AssignmentId, cuser_name = User.Identity.Name }; JournalRep.AddOrUpdate(journal_record); InstAssignmentRep.Delete(a); return(Json(new { success = true }, JsonRequestBehavior.AllowGet)); } catch (Exception) { return(Json(new { success = false }, JsonRequestBehavior.AllowGet)); } }
//=================================================PHOTOES============== public ActionResult UploadFile(int?entityId) { var statuses = new List <ViewDataUploadFileResult>(); for (var i = 0; i < Request.Files.Count; i++) { var st = FileSaver.StoreFile(x => { x.File = Request.Files[i]; x.DeleteUrl = Url.Action("DeleteFile", new { entityId = entityId }); x.StorageDirectory = Server.MapPath("~/Content/uploads"); x.UrlPrefix = "/Content/uploads"; x.FileName = Request.Files[i].FileName; x.ThrowExceptions = true; }); Photo p = new Photo() { PathPhoto = "/Content/uploads/" + Request.Files[i].FileName, GoodId = Convert.ToInt32(entityId) }; repophoto.AddOrUpdate(p); statuses.Add(st); } statuses.ForEach(x => x.thumbnailUrl = x.url + "?width=80&height=80"); statuses.ForEach(x => x.url = Url.Action("DownloadFile", new { fileUrl = x.url, mimetype = x.type })); var viewresult = Json(new { files = statuses }); if (Request.Headers["Accept"] != null && !Request.Headers["Accept"].Contains("application/json")) { viewresult.ContentType = "text/plain"; } return(viewresult); }
private void Sync <TEntity>(IGenericRepository <TEntity> repository, IList <TEntity> entities) where TEntity : class, IEntity { foreach (var entity in entities) { repository.AddOrUpdate(entity); } }
public TDtoElement AddOrUpdate(TDtoElement item) { var target = m_mapper.Map <TDbElement>(item); m_repository.AddOrUpdate(target); m_repository.Save(); return(m_mapper.Map <TDtoElement>(target)); }
public ActionResult EditDetail(Good g) { if (ModelState.IsValid) { repogood.AddOrUpdate(g); } return(RedirectToAction("Index")); }
public PhotoDTO Add(PhotoDTO obj) { Photo photo = _mapper.Map <Photo>(obj); photoRepository.AddOrUpdate(photo); photoRepository.Save(); return(_mapper.Map <PhotoDTO>(photo)); }
public SaleposDTO Add(SaleposDTO obj) { Salepos sale = _mapper.Map <Salepos>(obj); saleposRepository.AddOrUpdate(sale); saleposRepository.Save(); return(_mapper.Map <SaleposDTO>(sale)); }
public bool JoinGroup(string userId, int groupId) { var user = _userRepository.Get.FirstOrDefault(u => u.Id == userId); var group = _groupRepository.Get.FirstOrDefault(g => g.Id == groupId); group.JoinedUsers.Add(user); _groupRepository.AddOrUpdate(group); return(true); }
public HttpResponseMessage Post([FromBody] BizEmployee emp) { BizEmployeeRep.AddOrUpdate(emp); var msg = Request.CreateResponse(HttpStatusCode.Created, emp); string url = Url.Link("DefaultApi", new { id = emp.EmployeeId }); msg.Headers.Location = new Uri(url); return(msg); }
public void PersonAddOrUpdate() { try { var person = _personRepo.AddOrUpdate(new Person { Name = "Musa", Surname = "DEMÝR " + DateTime.Now }); person.Name = person.Name + " - " + DateTime.Now; _personRepo.AddOrUpdate(person); } catch (Exception e) { Assert.That(false, "Error: " + e.Message); } Assert.Pass(); }
public void SoftUpdateableAddOrUpdate() { try { var score = _studentCourseScoreRepo.AddOrUpdate(new StudentCourseScore { FKCourseID = 5, FKStudentID = 8 }); score.FKStudentID = 99; _studentCourseScoreRepo.AddOrUpdate(score); } catch (Exception e) { Assert.That(false, "Error: " + e.Message); } Assert.Pass(); }