public IActionResult AddRecord(CreateRecordViewModel model) { if (ModelState.IsValid) { string uniqueFileName = null; if (model.Document != null) { string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images"); uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Document.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); model.Document.CopyTo(new FileStream(filePath, FileMode.Create)); } Record record = new Record { PatientID = model.PatientID, Description = model.Description, Document = uniqueFileName }; recordeService.insert(record); return(RedirectToAction("Edit", "Patients", new { id = record.PatientID })); } return(View()); }
public async Task <IActionResult> CreateRecord(CreateRecordViewModel model) { var user = await GetCurrentUserAsync(); if (!ModelState.IsValid) { model.Recover(user); return(View(model)); } var app = await _dbContext.Apps.FindAsync(model.AppId); if (app == null) { return(NotFound()); } if (app.CreatorId != user.Id) { return(Unauthorized()); } try { var token = await _appsContainer.AccessToken(app.AppId, app.AppSecret); await _recordsService.CreateNewRecordAsync(token, model.RecordName, model.URL, model.Tags?.Split(',') ?? Array.Empty <string>(), model.Type, model.Enabled); return(RedirectToAction(nameof(AppsController.ViewApp), "Apps", new { id = app.AppId, JustHaveUpdated = true })); } catch (AiurUnexpectedResponse e) { ModelState.AddModelError(string.Empty, e.Response.Message); model.Recover(user); return(View(model)); } }
public async Task <IActionResult> Edit(int id, CreateRecordViewModel model) { if (ModelState.IsValid) { string uniqueFileName = null; if (model.Document != null) { string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images"); uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Document.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); model.Document.CopyTo(new FileStream(filePath, FileMode.Create)); } Record record = new Record() { Description = model.Description, PatientID = model.PatientID, Document = uniqueFileName }; try { recordeService.Update(record, id); } catch { } return(RedirectToAction(nameof(Index))); } return(View(model)); }
public CreateRecordViewModel CreateRentalRecord() { var customerInfo = _context.Customers; var movieInfo = _context.Movies; var newRecord = new CreateRecordViewModel { Customers = customerInfo.ToList(), Movies = movieInfo.ToList(), }; return(newRecord); }
public async Task <ActionResult> Create(CreateRecordViewModel model) { if (!ModelState.IsValid) { return(Json(ModelState.ToDictionary())); } var agentId = User.Identity.GetUserId(); var record = await _contactsDiaryServices.CreateRecord(model, agentId); return(Json(record)); }
public IHttpActionResult Post([FromBody] CreateRecordViewModel model) { if (model == null) { return(BadRequest()); } Record record = new Record { Name = model.Name, CreateDate = model.CreateDate, Description = model.Description, CategoryId = model.CategoryId, PictureId = model.PictureId }; recordService.Create(record); return(Ok()); }
public IActionResult Edit(int?id) { if (id == null) { return(NotFound()); } var record = recordeService.GetOne(id); if (record == null) { return(NotFound()); } CreateRecordViewModel model = new CreateRecordViewModel { Description = record.Description, PatientID = record.PatientID }; ViewBag.Document = record.Document; return(View(model)); }
public async Task <IActionResult> CreateRecord([FromRoute] string appId)// app id { var user = await GetCurrentUserAsync(); var app = await _dbContext.Apps.FindAsync(appId); if (app == null) { return(NotFound()); } if (app.CreatorId != user.Id) { return(Unauthorized()); } var model = new CreateRecordViewModel(user) { AppId = appId, AppName = app.AppName }; return(View(model)); }
public async Task <RecordListViewModel> CreateRecord(CreateRecordViewModel model, string agentId) { if (!await IsAgentExisting(agentId)) { throw new ArgumentException("Агентът, не е намерен!"); } var record = new ContactsDiary { Address = model.Address, AdditionalDescription = model.AdditionalDescription, AgentId = agentId, CityDistrict = model.CityDistrict, CityId = model.CityId, ContactedPersonTypeId = model.ContactedPersonTypeId, DealTypeId = model.DealTypeId, Name = model.Name, NegotiationStateId = model.NegotiationStateId, PhoneNumber = model.PhoneNumber, PropertySource = model.PropertySource, PropertyTypeId = model.PropertyTypeId }; dbContext.ContactsDiary.Add(record); await dbContext.SaveChangesAsync(); var createdClient = await dbContext.ContactsDiary .Include(r => r.Agent) .Include(r => r.NegotiationState) .Include(r => r.ContactedPersonType) .Include(r => r.DealType) .Include(r => r.PropertyType) .Where(c => c.Id == record.Id).Select(r => new RecordListViewModel { Id = r.Id, CreatedOn = r.CreatedOn, PhoneNumber = r.PhoneNumber, Name = r.Name, CityId = r.CityId, CityName = r.City.CityName, CityDistrict = r.CityDistrict, Address = r.Address, PropertySource = r.PropertySource, AdditionalDescription = r.AdditionalDescription, ContactedPersonTypeId = r.ContactedPersonTypeId, ContactedPersonType = r.ContactedPersonType.ContactedPersonType, DealTypeId = r.DealTypeId, DealType = r.DealType.DealType, PropertyTypeId = r.PropertyTypeId, PropertyType = r.PropertyType.PropertyTypeName, NegotiationStateId = r.NegotiationStateId, NegotiationState = r.NegotiationState.State, RecordColor = r.NegotiationState.Color, AgentId = r.AgentId, AgentName = r.Agent.FirstName + " " + r.Agent.LastName }) .FirstOrDefaultAsync() ?? throw new ContentNotFoundException("Не е намерен записът!"); #region Notifications var notificationToCreate = new NotificationCreateViewModel { NotificationTypeId = (int)NotificationType.Contact, NotificationPicture = "", NotificationLink = "/contactsdiary/index?contactId=" + record.Id, NotificationText = createdClient.AgentName + " добави контакт: " + createdClient.ContactedPersonType + " - тел:" + createdClient.PhoneNumber }; await notificationCreator.CreateGlobalNotification(notificationToCreate, agentId); #endregion return(createdClient); }