public async Task <ActionResult> Edit(ItemTypeViewModel itemType) { if (!ModelState.IsValid) { return(View(itemType)); } var editItemType = await _db.ItemTypes.FindAsync(itemType.TypeId); if (editItemType == null) { return(HttpNotFound()); } editItemType.Name = itemType.Name; editItemType.Attributes.Clear(); foreach (var attrId in itemType.AttributeIds.Where(a => a != null).Distinct()) { var attribute = await _db.ItemAttributes.FindAsync(attrId); if (attribute != null) { editItemType.Attributes.Add(attribute); } } _db.Entry(editItemType).State = EntityState.Modified; await _db.SaveChangesAsync(); return(RedirectToAction("Index")); }
private async Task <List <ItemTypeViewModel> > GetItemTypesAsync(ItemTypeViewModel itemTypeViewModel) { try { string actionPath = "Listing/GetCatogries"; ResponseModel responseContent = null; using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(CommonFunction.GetWebAPIBaseURL());; client.DefaultRequestHeaders.Authorization = AuthHandler.AuthenticationHeader(); //client.BaseAddress = new Uri(path); HttpResponseMessage response = await client.PostAsJsonAsync(actionPath, itemTypeViewModel); if (response.IsSuccessStatusCode) { responseContent = await response.Content.ReadAsAsync <ResponseModel>(); } } if (responseContent != null && responseContent.Success) { var json = JsonConvert.SerializeObject(responseContent.Data); var itemsResponseModel = JsonConvert.DeserializeObject <List <ItemTypeViewModel> >(json); return(itemsResponseModel); } else { return(null); } } catch (Exception ex) { throw; } }
public async Task <IActionResult> Create([FromForm] ItemTypeViewModel viewModel) { try { if (ModelState.IsValid) { var newType = Mapper.Map <ItemType>(viewModel); newType.CreateDate = DateTime.Now; newType.UserId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); var exist = _repository.Get(w => string.Equals(w.Name, viewModel.Name, StringComparison.CurrentCultureIgnoreCase)); if (exist != null) { TempData["itemType"] = "Item Type already exist."; } else { _repository.Insert(newType); if (await _repository.SaveChangesAsync()) { TempData["itemType"] = "Item Type is successfully created."; } } } } catch (Exception ex) { _logger.LogError(ex.Message); } return(RedirectToAction("Index")); }
public JsonResult AddItemType(ItemTypeViewModel itemType) { try { var itemTypeList = db.ItemType.ToList(); if (ModelState.IsValid) { if (itemType.ItemTypeName == null) { return(Json(itemTypeList)); } var itemTypeModel = new ItemType(); itemTypeModel.ItemTypeName = itemType.ItemTypeName; itemTypeModel.Status = true; itemTypeModel.UserName = WebSecurity.CurrentUserName; itemTypeModel.ModifiedDate = DateTime.Now; UpdateModel(itemTypeModel); db.ItemType.Add(itemTypeModel); db.Entry(itemTypeModel).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); itemTypeList.Add(itemTypeModel); } return(Json(itemTypeList)); } catch (Exception ex) { logger.Log(LogLevel.Error, "Exception occurred in Settings -> AddItemType[HTTPGET]: " + ex.Message); throw; } }
public PartialViewResult CreateItemType(int id) { var model = new ItemTypeViewModel(); if (id > 0) { model = AutomapperConfig.Mapper.Map <ItemTypeViewModel>(db.ItemTypeRepo.GetById(id)); } if (model == null) { Response.StatusCode = (int)HttpStatusCode.OK; return(PartialView(BadRequestView)); } return(PartialView(model)); }
public ActionResult AddItemType(ItemTypeViewModel itemTypeViewModel) { using (var inventoryContext = new InventoryContext()) { var itemType = new ItemType { ItemTypeDisplayName = itemTypeViewModel.ItemTypeDisplayName, ItemTypeNotes = itemTypeViewModel.ItemTypeNotes }; inventoryContext.ItemTypes.Add(itemType); inventoryContext.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult DeleteItemType(ItemTypeViewModel itemTypeViewModel) { using (var inventoryContext = new InventoryContext()) { var itemType = inventoryContext.ItemTypes.SingleOrDefault(p => p.ItemTypeId == itemTypeViewModel.ItemTypeId); if (itemType != null) { inventoryContext.ItemTypes.Remove(itemType); inventoryContext.SaveChanges(); return(RedirectToAction("Index")); } } return(new HttpNotFoundResult()); }
public JsonResult EditItemTypeItem(int id) { try { var itemType = db.ItemType.Find(id); ItemTypeViewModel ItemTypeViewModel = new ItemTypeViewModel(); ItemTypeViewModel.Id = itemType.Id; ItemTypeViewModel.ItemTypeName = itemType.ItemTypeName; return(Json(ItemTypeViewModel, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { logger.Log(LogLevel.Error, "Exception occurred in Settings -> EditItemTypeItem[HTTPGET]: " + ex.Message); throw; } }
public ActionResult EditItemType(ItemTypeViewModel itemTypeViewModel) { using (var inventoryContext = new InventoryContext()) { var itemType = inventoryContext.ItemTypes.SingleOrDefault(p => p.ItemTypeId == itemTypeViewModel.ItemTypeId); if (itemType != null) { itemType.ItemTypeDisplayName = itemTypeViewModel.ItemTypeDisplayName; itemType.ItemTypeNotes = itemTypeViewModel.ItemTypeNotes; inventoryContext.SaveChanges(); return(RedirectToAction("Index")); } } return(new HttpNotFoundResult()); }
public ActionResult SaveItemType(ItemTypeViewModel itemTypeViewModel) { bool isSuccess = false; if (ModelState.IsValid) { try { ItemTypeDTO dto = new ItemTypeDTO(); AutoMapper.Mapper.Map(itemTypeViewModel, dto); isSuccess = _itemTypeBusiness.SaveItemType(dto, UserId, OrgId); } catch (Exception ex) { isSuccess = false; } } return(Json(isSuccess)); }
public async Task <ActionResult> Create(ItemTypeViewModel itemType) { if (!ModelState.IsValid) { return(View(itemType)); } _db.ItemTypes.Add(new ItemType { Name = itemType.Name, Attributes = itemType.AttributeIds .Where(a => a != null) .Distinct() .Select(item => _db.ItemAttributes.FirstOrDefault(a => a.Id == item)) .ToList() }); await _db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public ActionResult ItemTypeEdit(int id) { using (var inventoryContext = new InventoryContext()) { var itemType = inventoryContext.ItemTypes.SingleOrDefault(p => p.ItemTypeId == id); if (itemType != null) { var itemTypeViewModel = new ItemTypeViewModel { ItemTypeId = itemType.ItemTypeId, ItemTypeDisplayName = itemType.ItemTypeDisplayName, ItemTypeNotes = itemType.ItemTypeNotes }; return(View("AddEditItemType", itemTypeViewModel)); } } return(new HttpNotFoundResult()); }
public JsonResult DeleteItemType(ItemTypeViewModel itemType) { try { var itemTypeItemDetails = new ItemTypeViewModel(); var itemTypeList = db.ItemType.ToList(); var itemTypeToUpdate = new ItemType(); if (itemType == null || !ModelState.IsValid) { return(Json(itemType)); } itemTypeToUpdate = db.ItemType.Find(itemType.Id); if (itemTypeToUpdate == null) { return(Json(itemTypeList)); } itemTypeToUpdate.Status = false; itemTypeToUpdate.ItemTypeName = itemType.ItemTypeName; itemTypeToUpdate.UserName = WebSecurity.CurrentUserName; itemTypeToUpdate.ModifiedDate = DateTime.Now; if (TryUpdateModel(itemTypeToUpdate, "Status")) { db.Entry(itemTypeToUpdate).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); itemTypeList = db.ItemType.ToList(); } return(Json(itemTypeItemDetails)); } catch (Exception ex) { logger.Log(LogLevel.Error, "Exception occurred in Settings -> DeleteItemType[HTTPGET]: " + ex.Message); throw; } }
public async Task <PartialViewResult> FetchItemTypesPartialAsync(ItemTypeViewModel itemTypeViewModel) { List <ItemTypeViewModel> items = await GetItemTypesAsync(itemTypeViewModel); return(PartialView("~/Views/List/_ListItemTypePartial.cshtml", items)); }
public ActionResult ItemTypeAdd() { var itemTypeViewModel = new ItemTypeViewModel(); return(View("AddEditItemType", itemTypeViewModel)); }
public string PostAddCandidate([FromHeader] string Firstname, [FromHeader] string Surname, [FromHeader] string Idnumber, [FromHeader] string CompanyName, [FromHeader] string IDVerification, [FromHeader] string CrimCheck) { string result = ""; try { CreatorEntities creatordb = new CreatorEntities(); VALINFOEntities valinfodb = new VALINFOEntities(); string username = User.Identity.GetUserName().ToString(); Client client = valinfodb.Clients.Single(x => x.CompanyName == CompanyName); Candidate candidate = valinfodb.Candidates.Where(x => x.IDNumber == Idnumber && x.ClientID == client.ClientID && x.AppUserID == username).SingleOrDefault(); if (candidate == null) { candidate.Firstname = Firstname; candidate.Surname = Surname; candidate.IDNumber = Idnumber; candidate.Cellphone = "0760619183"; candidate.ClientID = client.ClientID; candidate.AppUserID = User.Identity.GetUserName(); valinfodb.Candidates.Add(candidate); valinfodb.SaveChanges(); } var localRequest = new MieRequest() { CandidateID = candidate.CandidateID, ClientID = candidate.ClientID, Date = DateTime.Now, RequestType = 0, UserID = "433a858b-3b33-4c65-92df-b8eea190ecf9" }; valinfodb.MieRequests.Add(localRequest); valinfodb.SaveChanges(); if (candidate != null && Convert.ToBoolean(IDVerification)) { ItemTypeViewModel itemTypeViewModel = new ItemTypeViewModel(); itemTypeViewModel.Code = "IDALG"; itemTypeViewModel.Name = "MIE ID Validation"; itemTypeViewModel.IsActive = true; List <ItemTypeViewModel> itemTypeViewModelList = new List <ItemTypeViewModel>(); itemTypeViewModelList.Add(itemTypeViewModel); var items = new List <ItemType>(); items = Services.ItemTypes.Join(itemTypeViewModelList, x => x.Code, i => i.Code, (x, i) => x).Distinct().ToList(); var requestModel = new MieRequestModel(); requestModel.Request = new Models.Request() { ClientKey = Services.Client.Key, AgentKey = Services.Agent.Key, AgentClient = Services.Agent.ClientKey, FirstNames = candidate.Firstname, Surname = candidate.Surname, KnownAs = candidate.Firstname, IdNumber = !string.IsNullOrWhiteSpace(candidate.IDNumber) ? candidate.IDNumber : "", Passport = !string.IsNullOrWhiteSpace(candidate.Passport) ? candidate.Passport : "", DateOfBirth = candidate.BirthDate.HasValue ? candidate.BirthDate.Value.ToString("s") : IdNumberToDateOfBirth(candidate.IDNumber), Source = Constants.MieRequestSource, RemoteCaptureDate = DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffK"), RemoteSendDate = DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffK"), ContactNumber = "", RemoteRequest = localRequest.RequestID.ToString(), PrerequisiteGroupList = new PrerequisiteGroupList(), ItemList = new ItemList() { Item = new List <MieItem>() } }; foreach (var item in items.Select((value, i) => new { i, value })) { var requestItem = new MieRequestItem { IsPackageItem = false, Amount = GetProductAmount(item.value.Code, client.Category, client.ClientID, null), ClientID = candidate.ClientID, ItemCode = item.value.Code, RequestID = localRequest.RequestID }; valinfodb.MieRequestItems.Add(requestItem); valinfodb.SaveChanges(); requestModel.Request.ItemList.Item.Add(new MieItem { RemoteItemKey = requestItem.RequestItemID.ToString(), ItemTypeCode = item.value.Code, Indemnity = (!string.IsNullOrEmpty(item.value.IndemnityType) && !item.value.IndemnityType.Equals("none", StringComparison.InvariantCultureIgnoreCase)) ? "true" : "false", // Handle Input groups and attributes ItemInputGroupList = GetInputGroupList(item.value, itemTypeViewModelList) }); } try { // Post request var data = Services.PutRequest(requestModel); // Create user action if (data != null && data.Status != null && data.Status.Code == "0") { if (data.Request != null) { localRequest.Status = (int)MieRequestStatus.NoResult; // No results returned yet. localRequest.MieRequestID = Convert.ToInt64(data.Request.RequestKey); valinfodb.SaveChanges(); } candidate.VettingStatus = 1; candidate.DateModified = DateTime.UtcNow.AddHours(2); valinfodb.SaveChanges(); } else { var itemsToDelete = valinfodb.MieRequestItems.Where(x => x.RequestID == localRequest.RequestID); valinfodb.MieRequestItems.RemoveRange(itemsToDelete); valinfodb.MieRequests.Remove(localRequest); valinfodb.SaveChanges(); return(data.Status.Description); } } catch (Exception ex) { var itemsToDelete = valinfodb.MieRequestItems.Where(x => x.RequestID == localRequest.RequestID); valinfodb.MieRequestItems.RemoveRange(itemsToDelete); valinfodb.MieRequests.Remove(localRequest); valinfodb.SaveChanges(); return("Request failed, please try again."); } } if (candidate != null && Convert.ToBoolean(CrimCheck)) { } result = "success"; } catch (Exception ex) { result = "Error: " + ex.Message; } return(result); }