public ResponseMessage UpdateStructure(StructureDetails structureDetails, int id) { ResponseMessage responseMessage = new ResponseMessage(); try { var structure = _context.Structures.Where(x => x.Id == id && x.IsDelete == false).FirstOrDefault(); if (structure != null) { // if (_context.Structures.Where (x => x.Id != structureDetails.Id && x.IsDelete == false).Count () > 0) { // throw new ValueNotFoundException ("Structure already exist."); // } else { structure.IsActive = structureDetails.IsActive; structure.Name = structureDetails.Name; structure.StructureAttributesDef = structureDetails.StructureAttributes; structure.StructureTypeId = structureDetails.StructureTypeId; structure.UpdatedAt = DateTime.Now; _context.SaveChanges(); return(responseMessage = new ResponseMessage() { Message = "Structure updated successfully.", }); //} } else { throw new ValueNotFoundException("Structure not available."); } } catch (Exception ex) { throw ex; } }
public IActionResult AddStructure(StructureDetails structure) { try { //validate StructureAttributes dynamic structureAttr = JsonConvert.DeserializeObject(structure?.StructureAttributes); structure.StructureAttributes = JsonConvert.SerializeObject(structure?.StructureAttributes); } catch (Exception ex) { Util.LogInfo($"AddStructure: Issue with Deserialize StructureAttributes: {ex.Message}"); return(StatusCode(StatusCodes.Status400BadRequest, (new { message = "Issue with Deserialize StructureAttributes", code = 400 }))); } try { var response = _structureService.AddStructure(structure); return(StatusCode(StatusCodes.Status201Created, (new { message = response.Message, code = 201 }))); } catch (ValueNotFoundException e) { Util.LogError(e); return(StatusCode(StatusCodes.Status422UnprocessableEntity, new ErrorClass() { code = StatusCodes.Status422UnprocessableEntity.ToString(), message = e.Message })); } catch (Exception e) { Util.LogError(e); return(StatusCode(StatusCodes.Status500InternalServerError, new ErrorClass() { code = StatusCodes.Status500InternalServerError.ToString(), message = "Something went wrong" })); } }
public ResponseMessage UpdateStructure(StructureDetails structure, int id) { ResponseMessage responseMessage = new ResponseMessage(); responseMessage = _structureRepository.UpdateStructure(structure, id); return(responseMessage); }
public StructureDetails GetStructureById(int id) { StructureDetails structure = _structureRepository.GetStructureById(id); if (structure == null) { return(null); } return(structure); }
public StructureDetails GetStructureById(int id) { StructureDetails response = new StructureDetails(); var responsedb = _context.Structures.Where(x => x.Id == id && x.IsDelete == false).FirstOrDefault(); if (responsedb != null) { response = _mapper.Map <StructureDetails> (responsedb); } return(response); }
public ActionResult DefineStructure(StructureDetails viewModel) { IStructuredetailRepository objstruct = new StructuredetailRepository(); var validate = objstruct.Getcondition(viewModel.CompanyCode, viewModel.CityCode, viewModel.CityName).FirstOrDefault(); var validate1 = objstruct.Getcondition1(viewModel.CompanyCode, viewModel.CityCode).FirstOrDefault(); var validate3 = objstruct.Getcondition2(viewModel.CityCode, viewModel.CityName).FirstOrDefault(); var check = objstruct.Getcondition3(viewModel.CityCode).FirstOrDefault(); var check1 = objstruct.Getcondition4(viewModel.CityName).FirstOrDefault(); var check2 = objstruct.Getcondition5(viewModel.CompanyCode).FirstOrDefault(); if (validate == null && validate3 != null || validate1 == null && check1 == null || !objstruct.GetAll().Any()) { if (ModelState.IsValid) { objstruct.Add(viewModel.CompanyCode, viewModel.CityCode, viewModel.CompanyName, viewModel.CityName); objstruct.Save(); RedirectToAction("StructureList", "Home"); TempData["SuccessMessage"] = "Structure Created"; } else { TempData["ErrorMessage"] = "Unable to Add"; } } else if (validate1 != null) { TempData["ErrorMessage"] = ("CompanyCode " + viewModel.CompanyCode + " with CityCode " + viewModel.CityCode + "Already Exists"); } else if (validate3 != null) { TempData["ErrorMessage"] = ("City Code " + viewModel.CityCode + " with City " + viewModel.CityName + " already Exists"); } else if (validate != null && validate1 != null && validate3 != null) { TempData["ErrorMessage"] = ("Company Code " + viewModel.CompanyCode + " with City Code " + viewModel.CityCode + "and" + viewModel.CityName + " Already Exists"); } else { TempData["ErrorMessage"] = ("City with Name " + viewModel.CityName + " already Exists in Company Code " + viewModel.CompanyCode + ""); } return(View(viewModel)); }
public IActionResult GetStructureById(int id) { StructureDetails response = null; try { response = _structureService.GetStructureById(id); return(Ok(response)); } catch (Exception e) { Util.LogError(e); return(StatusCode(StatusCodes.Status500InternalServerError, new ErrorClass() { code = StatusCodes.Status500InternalServerError.ToString(), message = "Something went wrong" })); } finally { Util.LogInfo($"GetStructureById: {id}"); } }
// public StructureComponentDetails GetStructureCompById(int id) // { // StructureComponentDetails response = new StructureComponentDetails(); // var responsedb = _context.ProjectStructure.Include(c=>c.Component).Where(x => x.StructureId == id && x.IsDelete == false).ToList(); // if (responsedb != null) // response = _mapper.Map<StructureComponentDetails>(responsedb); // return response; // } public ResponseMessage AddStructure(StructureDetails structureDetails) { ResponseMessage response = new ResponseMessage(); try { var structureDb = _mapper.Map <Structures> (structureDetails); _context.Structures.Add(structureDb); _context.SaveChanges(); return(response = new ResponseMessage() { Message = "Structure added successfully." }); // } } catch (Exception ex) { throw ex; } }
public ResponseMessage AddStructure(StructureDetails structure) { ResponseMessage responseMessage = new ResponseMessage(); responseMessage = _structureRepository.AddStructure(structure); if (responseMessage != null) { return(responseMessage); } else { return(new ResponseMessage() { Message = "", }); } }
public IActionResult UpdateStructure(StructureDetails structure, int id) { try { var response = _structureService.UpdateStructure(structure, id); return(Ok(new { message = response.Message, code = 204 })); } catch (ValueNotFoundException e) { Util.LogError(e); return(StatusCode(StatusCodes.Status422UnprocessableEntity, new ErrorClass() { code = StatusCodes.Status422UnprocessableEntity.ToString(), message = e.Message })); } catch (Exception e) { Util.LogError(e); return(StatusCode(StatusCodes.Status500InternalServerError, new ErrorClass() { code = StatusCodes.Status500InternalServerError.ToString(), message = "Something went wrong" })); } }