public IActionResult AddSize(AddSizeModel addSizeModel) { try { if (ModelState.IsValid) { var sizeModel = SizeHelper.BindSizeModel(addSizeModel); var sizeDetailModel = SizeHelper.BindSizeDetailModel(addSizeModel); if (sizeModel.SizeId <= 0) { long sizeId = iSize.AddSize(sizeModel, sizeDetailModel); if (sizeId > 0) { return(Ok(ResponseHelper.Success(MessageConstants.SizeAdded))); } else if (sizeId == ReturnCode.AlreadyExist.GetHashCode()) { return(Ok(ResponseHelper.Error(MessageConstants.SizeExists))); } else { return(Ok(ResponseHelper.Error(MessageConstants.SizeNotAdded))); } } else { long sizeId = iSize.UpdateSize(sizeModel, sizeDetailModel); if (sizeId > 0) { return(Ok(ResponseHelper.Success(MessageConstants.SizeUpdated))); } else if (sizeId == ReturnCode.AlreadyExist.GetHashCode()) { return(Ok(ResponseHelper.Error(MessageConstants.TryDifferentName))); } else { return(Ok(ResponseHelper.Error(MessageConstants.SizeNotUpdated))); } } } else { return(Ok(ResponseHelper.Error(MessageConstants.CompulsoryData))); } } catch (Exception ex) { LogHelper.ExceptionLog(ex.Message + " ::::: " + ex.StackTrace); return(Ok(ResponseHelper.Error(ex.Message))); } }
/// <summary> /// Binds the size model. /// </summary> /// <param name="addSizeModel">The add size model.</param> /// <returns></returns> public static Size BindSizeModel(AddSizeModel addSizeModel) { Size sizeModel = new Size(); if (addSizeModel != null) { sizeModel.Name = addSizeModel.Name; if (!string.IsNullOrWhiteSpace(addSizeModel.SizeId) && DBHelper.ParseInt64(addSizeModel.SizeId) > 0) { sizeModel.SizeId = DBHelper.ParseInt64(addSizeModel.SizeId); } } return(sizeModel); }
/// <summary> /// Binds the size detail model. /// </summary> /// <param name="addSizeModel">The add size model.</param> /// <returns></returns> public static List <SizeDetail> BindSizeDetailModel(AddSizeModel addSizeModel) { List <SizeDetail> sizeDetialModel = new List <SizeDetail>(); if (addSizeModel != null) { string[] splittedUnits = addSizeModel.Units.Split(','); if (splittedUnits != null && splittedUnits.Length > 0) { foreach (var item in splittedUnits) { if (!string.IsNullOrWhiteSpace(item)) { sizeDetialModel.Add(new SizeDetail { Name = item }); } } } } return(sizeDetialModel); }