public async Task <ApiResponseResult> UpdateCategory(CategoryModel category) { ApiResponseResult apiResponseResult = new ApiResponseResult(); try { var _categpry = await _context.Categories.Where(x => x.categoryId == category.categoryId).FirstOrDefaultAsync(); if (_categpry != null) { _categpry.categoryDesc = category.categoryDesc; _categpry.categoryName = category.categoryName; if (category.categoryImage != null && category.categoryImage != "") { _categpry.categoryImage = category.categoryImage; } await _context.SaveChangesAsync(); apiResponseResult.message = "Category Updated Successfully"; apiResponseResult.ErrorCode = (int)Constant.Error.NO_ERROR; } else { apiResponseResult.message = "No Category found"; apiResponseResult.ErrorCode = (int)Constant.Error.RECIEVE_DATA_NULL; } } catch (Exception exc) { apiResponseResult.message = exc.Message; apiResponseResult.ErrorCode = (int)Constant.Error.EXCEPTION; } return(apiResponseResult); }
public async Task <int> Insert(TEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } string ip = string.Empty; Context.Entry(entity).State = EntityState.Added; var result = await Context.SaveChangesAsync(); return(result); }
public async Task <int> SaveDeliveryAddress(DeliveryInfoDTO deliveryInfoDTO) { DeliveryInfoModel deliveryInfoModel = new DeliveryInfoModel(); try { deliveryInfoModel.PersonName = deliveryInfoDTO.PersonName; deliveryInfoModel.PostalCode = deliveryInfoDTO.PostalCode; deliveryInfoModel.State = deliveryInfoDTO.State; deliveryInfoModel.ContactNumber = deliveryInfoDTO.ContactNumber; deliveryInfoModel.Address = deliveryInfoDTO.Address; _context.DeliveryInfo.Add(deliveryInfoModel); await _context.SaveChangesAsync(); return(deliveryInfoModel.Id); } catch (Exception exc) { throw exc; } }
public async Task <ApiResponseResult> UpdateProduct(ProductModel product) { ApiResponseResult apiResponseResult = new ApiResponseResult(); try { var prod = await _context.Products.Where(x => x.productId == product.productId).FirstOrDefaultAsync(); if (prod != null) { prod.productBrand = product.productBrand; prod.productDesc = product.productDesc; if (product.productImage != null && product.productImage != "") { prod.productImage = product.productImage; } prod.productName = product.productName; prod.productPrice = product.productPrice; prod.productWeight = product.productWeight; prod.categoryId = product.categoryId; await _context.SaveChangesAsync(); apiResponseResult.message = "Product Updated Successfully"; apiResponseResult.ErrorCode = (int)Constant.Error.NO_ERROR; } else { apiResponseResult.message = "No Product found"; apiResponseResult.ErrorCode = (int)Constant.Error.RECIEVE_DATA_NULL; } } catch (Exception exc) { apiResponseResult.message = exc.Message; apiResponseResult.ErrorCode = (int)Constant.Error.EXCEPTION; } return(apiResponseResult); }
public async Task <ApiResponseResult> SaveGuestInfo(GuestInfoDTO Guest, AddressDTO address) { User user = await getuser(Guest.email); ApiResponseResult apiresult = new ApiResponseResult(); if (user == null) { user = new User(); try { user.userPassword = "******"; user.firstName = Guest.firstName; user.lastName = Guest.lastName; user.userEmail = Guest.email; user.contact = Guest.phone; user.roleID = (Int32)Constant.User.GUEST_USER; user.joiningDate = DateTime.Now; user.street = address.street; user.state = address.state; user.userZipCode = address.zipCode; user.apartment = address.appartment; user.city = address.city; user.userAddress = address.street + "," + address.appartment + "," + address.city + "," + address.state + "," + address.zipCode; user.isActive = true; _context.Users.Add(user); await _context.SaveChangesAsync(); await SaveUserRole((Int32)Constant.User.GUEST_USER, user.userId); apiresult.ErrorCode = (int)Constant.Error.NO_ERROR; apiresult.data = user; apiresult.message = "Save Successfully"; } //catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) //{ // apiresult.ErrorNo = (int)Constant.Error.ENTITY_EXCEPTION; // apiresult.Message = dbEx.Message; // foreach (var validationErrors in dbEx.EntityValidationErrors) // { // foreach (var validationError in validationErrors.ValidationErrors) // { // string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // //raise a new exception inserting the current one as the InnerException // } // } //} catch (Exception exce) { apiresult.ErrorCode = (int)Constant.Error.EXCEPTION; apiresult.message = exce.Message; } } else { apiresult.ErrorCode = (int)Constant.Error.GUEST_ALREADY_EXIST; apiresult.message = "Guest Already Exist"; } return(apiresult); }