// Return fiscal year based on ID public FiscalYearViewModel GetFiscalYearByID(Guid id) { try { var response = _context.FiscalYears.Where(fy => fy.FiscalYearID.Equals(id)).SingleOrDefault(); var fiscalYear = new FiscalYearViewModel() { FiscalYearID = response.FiscalYearID, TextualFiscalYearMain = response.TextualFiscalYear, FullNumericFiscalYearMain = response.FullNumericFiscalYear }; if (fiscalYear != null) { return(fiscalYear); } else { return(null); } } catch (Exception) { return(null); } }
// Update fiscal year data based on ID public bool EditFiscalYearByID(FiscalYearViewModel fiscalyear) { try { var fiscalYearToBeUpdated = _context.FiscalYears.SingleOrDefault(fy => fy.FiscalYearID.Equals(fiscalyear.FiscalYearID)); if (fiscalYearToBeUpdated != null) { // Update informations of object fiscalYearToBeUpdated.FullNumericFiscalYear = fiscalyear.FullNumericFiscalYearMain; fiscalYearToBeUpdated.TextualFiscalYear = fiscalyear.TextualFiscalYearMain; var response = _context.SaveChanges(); return(true); } else { return(false); } } catch (Exception) { return(false); } }
// Adds a new fiscal year to the system. public bool AddNewFiscalYear(FiscalYearViewModel fiscalyear) { try { var fiscalYearToBeSaved = new FiscalYear() { FiscalYearID = fiscalyear.FiscalYearID, FullNumericFiscalYear = fiscalyear.FullNumericFiscalYearMain, TextualFiscalYear = fiscalyear.TextualFiscalYearMain }; _context.FiscalYears.Add(fiscalYearToBeSaved); var response = _context.SaveChanges(); if (response > 0) { return(true); } else { return(false); } } catch (Exception) { return(false); } }
public async Task <IActionResult> Edit(FiscalYearViewModel model) { model.SystemUserId = UserId; if (ModelState.IsValid) { model.StartDate = model.JalaliStartDate.ToDateTime(); model.EndDate = model.JalaliEndDate.ToDateTime(); var item = _mapper.Map <FiscalYearViewModel, FiscalYear>(model); var result = await _fiscalYearRepository.UpdateAsync(item); ErrorMessage = Resources.Messages.ChangesSavedSuccessfully; if (Request.Form.Keys.Contains("SaveAndReturn")) { return(RedirectToAction("Index")); } else { return(RedirectToAction("Edit", new { id = item.Id })); } } return(View(model)); }
// Mount edit fiscal year page based on ID public IActionResult Edit(Guid id) { try { // Getting uniqueName var uniqueName = HttpContext.User.Claims.First(claim => claim.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name").Value; // Getting the selected fiscal year var fiscalYearToBeViewed = Util.ConnectToRemoteService <FiscalYearViewModel>(HttpMethod.Get, Util.KanbanURL + "api/fiscalyear/getfiscalyearbyid?id=" + id, uniqueName, "").Result; if (fiscalYearToBeViewed != null) { var finalFiscalYear = new FiscalYearViewModel() { FiscalYearID = fiscalYearToBeViewed.FiscalYearID, FullNumericFiscalYearMain = fiscalYearToBeViewed.FullNumericFiscalYearMain, TextualFiscalYearMain = fiscalYearToBeViewed.TextualFiscalYearMain }; return(View(finalFiscalYear)); } else { return(View()); } } catch (Exception) { return(View()); } }
/// <summary> /// Delete an entity. /// </summary> /// <param name="model"></param> public void Delete(FiscalYearViewModel model) { var entity = model.ToEntity(); this._FiscalYearsRepository.Delete(entity); #region Commit Changes this._unitOfWork.Commit(); #endregion }
public bool AddNewFiscalYear(FiscalYearViewModel fiscalyear) { var fy = new FiscalYear() { _id = fiscalyear.FiscalYearID.ToString(), fullNumericFiscalYear = fiscalyear.FullNumericFiscalYearMain, textualFiscalYear = fiscalyear.TextualFiscalYearMain }; _context.FiscalYears.InsertOne(fy); return(true); }
// Return fiscal year based on ID public FiscalYearViewModel GetFiscalYearByID(Guid id) { var response = _context.FiscalYears.Where(fy => fy.FiscalYearID.Equals(id)).SingleOrDefault(); var fiscalYear = new FiscalYearViewModel() { FiscalYearID = response.FiscalYearID, TextualFiscalYearMain = response.TextualFiscalYear, FullNumericFiscalYearMain = response.FullNumericFiscalYear }; return(fiscalYear); }
public bool EditFiscalYearByID(FiscalYearViewModel fiscalyear) { // WARNING: impacts all Metrics!!! var byID = new BsonDocument { { nameof(FiscalYear._id), fiscalyear.FiscalYearID.ToString() } }; var updateColumns = Builders <FiscalYear> .Update .Set(nameof(FiscalYear.fullNumericFiscalYear), fiscalyear.FullNumericFiscalYearMain) .Set(nameof(FiscalYear.textualFiscalYear), fiscalyear.TextualFiscalYearMain); var fiscalYear = _context.FiscalYears.UpdateOne(byID, updateColumns); return(true); }
/// <summary> /// Throw an exception if name is exist. /// </summary> /// <param name="model">FiscalYear view model</param> public void ThrowExceptionIfExist(FiscalYearViewModel model) { ConditionFilter <FiscalYear, long> condition = new ConditionFilter <FiscalYear, long> { Query = (entity => entity.Name == model.Name && entity.Id != model.Id) }; var existEntity = this._FiscalYearsRepository.Get(condition).FirstOrDefault(); if (existEntity != null) { throw new ItemAlreadyExistException(); } }
/// <summary> /// Update an entity. /// </summary> /// <param name="model"></param> /// <returns></returns> public FiscalYearViewModel Update(FiscalYearViewModel model) { this.ThrowExceptionIfExist(model); var entity = model.ToEntity(); entity = this._FiscalYearsRepository.Update(entity); #region Commit Changes this._unitOfWork.Commit(); #endregion model = entity.ToModel(); return(model); }
public JsonResult EditFiscalYear(FiscalYearViewModel fiscalyear) { if (fiscalyear == null) { return(Json(new { Status = "Fail" })); } // Getting uniqueName var uniqueName = HttpContext.User.Claims.First(claim => claim.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name").Value; // Getting the selected fiscal year var responseAboutUpdate = Util.ConnectToRemoteService(HttpMethod.Put, Util.KanbanURL + "api/fiscalyear/editfiscalyearbyid", uniqueName, "", fiscalyear).Result; if (responseAboutUpdate.IsSuccessStatusCode) { return(Json(new { Status = "Ok" })); } else { return(Json(new { Status = "Fail" })); } }