public async Task <ActionResult> UpdateWarehouse(int id, [FromBody] WareHouseDto dto) { if (id != dto.Id) { return(BadRequest()); } foreach (var item in dto.Content) { var editedData = await _context.WareHourses.FirstOrDefaultAsync(s => s.Language.code == item.Languagename && s.MainId == id); editedData.Category = dto.Category; editedData.Name = item.Content; try { _context.Entry(editedData).State = EntityState.Modified; await _context.SaveChangesAsync(); } catch (Exception) { throw; } } return(Ok()); }
public static Infrastructure.Entities.WareHouse DtoToEntity(WareHouseDto dto) { return(new Infrastructure.Entities.WareHouse { Id = dto.Id, Name = dto.Name, CreatedBy = dto.CreatedBy, UpdatedBy = dto.UpdatedBy, UpdatedDate = DateTime.Now }); }
public static WareHouseViewModel DtoToViewModel(WareHouseDto dto) { return(new WareHouseViewModel { Id = dto.Id, Name = dto.Name, CreatedBy = dto.CreatedBy, UpdatedBy = dto.UpdatedBy, CreatedDate = dto.CreatedDate, UpdatedDate = dto.UpdatedDate, }); }
public static Entities.Warehouse DtoToEntity(WareHouseDto dto) { return(new Entities.Warehouse { Id = dto.Id, Name = dto.Name, Address = dto.Address, City = dto.City, CountryId = dto.CountryId, ProvinceId = dto.ProvinceId, PhoneNumber = dto.PhoneNumber, PostalCode = dto.PostalCode, CreatedBy = dto.CreatedBy, UpdatedBy = dto.UpdatedBy, UpdatedDate = DateTime.Now }); }
public static WareHouseViewModel DtoToViewModel(WareHouseDto dto) { return(new WareHouseViewModel { Id = dto.Id, Name = dto.Name, Address = dto.Address, City = dto.City, CountryId = dto.CountryId, CountryName = dto.CountryName, ProvinceId = dto.ProvinceId, ProvinceName = dto.ProvinceName, PhoneNumber = dto.PhoneNumber, PostalCode = dto.PostalCode, UpdatedBy = dto.UpdatedBy, UpdatedDate = dto.UpdatedDate, }); }
public async Task <ActionResult> GetWareHouse(string lang, int id) { var datalist = await _context.WareHourses.Include(s => s.Language).Where(s => s.MainId == id).ToListAsync(); List <LangcontentDto> content = datalist.Select(s => new LangcontentDto() { Languagename = s.Language.code, Content = s.Name }).ToList(); WareHouseDto data = new WareHouseDto() { Id = datalist.FirstOrDefault().Id, Category = datalist.FirstOrDefault().Category, Content = content }; return(Ok(data)); }
public IHttpActionResult LoadingWareHouse(WareHouseDto wareHouseDto) { IdentityUser user = db.Users.Where(a => a.UserName == ControllerContext.RequestContext.Principal.Identity.Name).FirstOrDefault(); if (user == null) { var response = new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("User doesn't exist."), StatusCode = HttpStatusCode.NotFound }; throw new HttpResponseException(response); } if (wareHouseDto == null) { var response = new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("wareHouseDto Parameter doesn't exist."), StatusCode = HttpStatusCode.NotFound }; throw new HttpResponseException(response); } var p = db.BuyingProducts.Where(a => a.IsLoading == false).ToList(); if (p == null || p.Count == 0) { var response = new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("there is not product to load."), StatusCode = HttpStatusCode.NotFound }; throw new HttpResponseException(response); } loadingProduct(p, wareHouseDto.MargenGain, user.Id); return(Ok("warehouse was loaded succesfully")); }
public async Task <ActionResult> AddWareHouse([FromBody] WareHouseDto dto) { int id = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); var logineduser = await _auth.VerifyUser(id); var count = await _context.WareHourses.CountAsync(); if (count == 0) { count++; } foreach (var item in dto.Content) { WareHourse wareHouse = new WareHourse() { MainId = count, Name = item.Content, Language = await _context.Languages.FirstOrDefaultAsync(s => s.code == item.Languagename), Category = dto.Category, Status = true, Company = logineduser.Company, }; try { await _context.WareHourses.AddAsync(wareHouse); await _context.SaveChangesAsync(); } catch (Exception) { throw; } } return(StatusCode(201)); }