public ShopDTO Insert(ShopDTO shop) { try { using (OpenNosContext context = DataAccessHelper.CreateContext()) { if (context.Shop.FirstOrDefault(c => c.MapNpcId.Equals(shop.MapNpcId)) == null) { Shop entity = new Shop(); Mapper.Mappers.ShopMapper.ToShop(shop, entity); context.Shop.Add(entity); context.SaveChanges(); if (Mapper.Mappers.ShopMapper.ToShopDTO(entity, shop)) { return(shop); } return(null); } return(new ShopDTO()); } } catch (Exception e) { Logger.Error(e); return(null); } }
//Returns the searches that found in that shop public static WebResult <SearchesForShop> getSearchesForShop([UserLogged] ShopDTO shopDTO) { using (ProjectEntities db = new ProjectEntities()) { SearchesForShop searchesForShop = new SearchesForShop(); foreach (var category in shopDTO.Categories) { //הוספת שם הקטגוריה searchesForShop.namesCategories.Add(category.nameCategory); //מתחילים לספור כמה יש מהקטגוריה הזו int counter = 0; foreach (var search in db.Searches) { if (search.codeCategory == category.codeCategory && search.codeShop == shopDTO.codeShop) { counter++; } } searchesForShop.numbersCategories.Add(counter); } return(new WebResult <SearchesForShop> { Message = "רשימת החיפושים לחנות נשלחה בהצלחה", Status = true, Value = searchesForShop }); } }
public async Task <ActionResult <ShopDTO> > PostShop(ShopDTO data) { var user = await model.Users.FindAsync(data.AuthorId); if (user == null) { return(BadRequest()); } var newShop = new Shop() { Title = data.Title, Description = data.Description, Timestamp = DateTime.Now, AuthorId = data.AuthorId, PicturePath = data.PicturePath, Type = data.Type }; model.Shops.Add(newShop); var res = await model.SaveChangesAsyncWithValidation(); if (!res.IsEmpty) { return(BadRequest(res)); } return(CreatedAtAction(nameof(GetOne), new { id = newShop.Id }, newShop.ToDTO())); }
public async Task <IActionResult> PUT(int id, ShopDTO data) { var shop = await model.Shops.FindAsync(id); if (shop == null) { return(NotFound()); } if (!(User.IsInRole(Role.Admin.ToString()) || shop.Author.Pseudo == User.Identity.Name)) { return(BadRequest()); } shop.Title = data.Title; shop.Description = data.Description; shop.Timestamp = DateTime.Now; shop.Type = data.Type; if (!string.IsNullOrWhiteSpace(data.PicturePath)) { shop.PicturePath = data.PicturePath + "?" + DateTime.Now.Ticks; } else { shop.PicturePath = null; } await model.SaveChangesAsyncWithValidation(); return(NoContent()); }
private void validate(ShopDTO shop) { if (string.IsNullOrEmpty(shop.Address)) { throw new ArgumentException("Address повинне містити значення!"); } }
public ShopDTO Insert(ShopDTO shop) { try { using (var context = DataAccessHelper.CreateContext()) { if (context.Shop.FirstOrDefault(c => c.MapNpcId.Equals(shop.MapNpcId)) == null) { Shop entity = _mapper.Map <Shop>(shop); context.Shop.Add(entity); context.SaveChanges(); return(_mapper.Map <ShopDTO>(entity)); } else { return(new ShopDTO()); } } } catch (Exception e) { Logger.Error(e); return(null); } }
//Register public async static Task <WebResult <LoginData <ShopDTO> > > Register(ShopDTO shopDto, Uri request) { using (ProjectEntities db = new ProjectEntities()) { if (db.Shops.FirstOrDefault(w => w.mailShop == shopDto.mailShop) != null)//אם יש כבר כזה מייל או כזו סיסמה { return new WebResult <LoginData <ShopDTO> > { Message = "משתמש כבר קיים במערכת", Status = false, Value = null } } ; List <CategoryDTO> sourceCats = shopDto.Categories; List <Category_to_shop> category_To_Shops = new List <Category_to_shop>(); foreach (var item in sourceCats) { db.Category_to_shop.Add(new Category_to_shop() { codeCategory = item.codeCategory, codeShop = shopDto.codeShop }); } db.Shops.Add(ShopCast.GetShop(shopDto)); try { if (db.SaveChanges() > 0)//בדיקה שהמידע נשמר { var accessToken = await GetTokenDataAsync(shopDto.mailShop, shopDto.passwordShop, request); if (!string.IsNullOrEmpty(accessToken)) { return(new WebResult <LoginData <ShopDTO> > { Status = true, Message = "התחברת בהצלחה", Value = new LoginData <ShopDTO> { TokenJson = accessToken, objectDTO = shopDto } }); } } } catch (Exception e) { var a = e.Data; } return(new WebResult <LoginData <ShopDTO> > { Status = false, Message = "ההרשמה נכשלה", Value = null }); } }
public Shop(ShopDTO input) { MapNpcId = input.MapNpcId; MenuType = input.MenuType; Name = input.Name; ShopId = input.ShopId; ShopType = input.ShopType; }
private UserShop GetShop(ShopDTO ShopDto) { var userShop = _context.UserShops .SingleOrDefault(o => o.UserId == ShopDto.UserId && o.ShopId == ShopDto.Id); return(userShop); }
public void UpdateShop(ShopDTO shopDto) { Shop shop = MappingUtil.MapInstance <ShopDTO, Shop>(shopDto); validator.Validate(shop); dataset.Shops.Update(shop); }
//Login public static async Task <WebResult <LoginData <ShopDTO> > > Login(string mail, string password, Uri requestUri) { using (ProjectEntities db = new ProjectEntities()) { var shop = db.Shops.Where(w => w.mailShop == mail).FirstOrDefault(); if (shop != null) { if (shop.passwordShop == password) { //אם המשתמש קיים במאגר המשך לקבלת טוקן, אחרת החזר שגיאה שהמתשמש לא קיים { ShopDTO shopDto = ShopCast.GetShopDTO(shop); List <int> codesCategories = db.Category_to_shop.Where(c => c.codeShop == shop.codeShop).Select(x => x.codeCategory).ToList(); //Category category; //shopDto.Categories = new List<CategoryDTO>(); //foreach (var item in codesCategories) //{ // category = db.Categories.Find(item); // if (category != null) // shopDto.Categories.Add(CategoryCast.GetCategoryDTO(category)); //} var accessToken = await GetTokenDataAsync(shopDto.mailShop, shopDto.passwordShop, requestUri); if (!string.IsNullOrEmpty(accessToken)) { return(new WebResult <LoginData <ShopDTO> > { Status = true, Message = "התחברת בהצלחה", Value = new LoginData <ShopDTO> { TokenJson = accessToken, objectDTO = shopDto } }); } } } else { return(new WebResult <LoginData <ShopDTO> > { Status = false, Message = " אין משתמש רשום בשם וסיסמא זו ", Value = null }); } } return(new WebResult <LoginData <ShopDTO> > { Status = false, Message = " אין משתמש רשום ", Value = null }); } }
public ActionResult <ShopDTO> GetShop(int id) { ShopDTO item = repository.Get(id); if (item == null) { return(NotFound()); } return(item); }
private static ShopDTO insert(ShopDTO account, OpenNosContext context) { Shop entity = new Shop(); Mapper.Mappers.ShopMapper.ToShop(account, entity); context.Shop.Add(entity); context.SaveChanges(); Mapper.Mappers.ShopMapper.ToShopDTO(entity, account); return(account); }
private void LoadReferences(IDbConnection db, ShopDTO entity) { const string productQuery = "SELECT p.* FROM Products as p INNER JOIN ProductShops as ps ON p.Id = ps.ProductId WHERE ps.ShopId = @Id"; entity.Products = mapper.Map <List <ProductDTO> >(db.Query <Product>(productQuery, entity)); const string requestDeliveriesQuery = "SELECT * FROM RequestDeliverys WHERE ShopId = @Id"; entity.RequestDeliveries = mapper.Map <List <RequestDeliveryDTO> >(db.Query <RequestDelivery>(requestDeliveriesQuery, entity)); }
public ShopDTO Get(int id) { using IDbConnection db = new SqlConnection(connectionString); const string query = "SELECT * FROM Shops WHERE Id = @Id"; ShopDTO entity = mapper.Map <ShopDTO>(db.QueryFirstOrDefault <Shop>(query, new { Id = id })); LoadReferences(db, entity); return(entity); }
public IHttpActionResult PostShop(ShopDTO shop) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } ShopDTO s = ShopBLL.Add(shop); return(Ok(s)); }
public IHttpActionResult GetShop(long id) { ShopDTO shop = ShopBLL.GetShopById(id); if (shop == null) { return(NotFound()); } return(Ok(shop)); }
/// <summary> /// Delete choosed product from database. /// </summary> /// <param name="shopDTO">ShopDTO.</param> public void DeleteProduct(ShopDTO shopDTO) { Console.Clear(); Console.WriteLine("Choose product to delete"); var entity = shopDTO.ProductLists.First().Products.ToList()[Convert.ToInt16(Console.ReadKey().KeyChar) - 49]; int productId = entity.ProductId; _unitOfWork.ProductRepository.Delete(productId); shopDTO.ProductLists.First().Products.Remove(entity); _unitOfWork.SaveChanges(); }
//Update shop with categories public static WebResult <ShopDTO> Update(ShopDTO shopDTO) { using (ProjectEntities db = new ProjectEntities()) { Shop shop = db.Shops.FirstOrDefault(f => f.mailShop == shopDTO.mailShop); //למייל אסור להשתנות if (shop == null) { return new WebResult <ShopDTO> { Message = "החנות לא נמצאה", Status = false, Value = null } } ; shop.nameShop = shopDTO.nameShop; shop.phoneShop = shopDTO.phoneShop; shop.latitude = shopDTO.latitude; shop.longitude = shopDTO.longitude; shop.fromHour = shopDTO.fromHour; shop.toHour = shopDTO.toHour; shop.addressString = shopDTO.addressString; List <CategoryDTO> sourceCats = shopDTO.Categories; //למחוק קודם את כל הקטגוריות של החנות List <Category_to_shop> category_To_Shops = db.Category_to_shop.ToList(); category_To_Shops.ForEach(item => { if (item.codeShop == shop.codeShop) { db.Category_to_shop.Remove(item); } }); db.SaveChanges(); // להוסיף את כל הקטגוריות החדשות לחנות foreach (var item in sourceCats) { db.Category_to_shop.Add(new Category_to_shop() { codeCategory = item.codeCategory, codeShop = shop.codeShop }); } db.SaveChanges(); return(new WebResult <ShopDTO> { Message = "הנתונים התעדכנו בהצלחה", Value = shopDTO, Status = true }); } }
public int RemoveLike(ShopDTO ShopDto) { var userShop = GetShop(ShopDto); if (userShop != null) { userShop.Like = false; userShop.ActionDate = DateTime.Now; _context.SaveChanges(); } return(userShop.ShopId); }
public Shop Post(ShopDTO value) { Shop model = new Shop() { Name = value.Name, Email = value.Email, Tel = value.Tel, Address = value.Address }; return(IShopRepository.Create(model)); }
/// <summary> /// Initializes a new instance of the <see cref="ShopPage"/> class. /// </summary> /// <param name="dataProvider">DataProvider.</param> /// <param name="account">Account.</param> /// <param name="shopDTO">ShopDTO.</param> public ShopPage(DataProvider dataProvider, AccountDTO account, ShopDTO shopDTO) : base(dataProvider, account) { _shopDTO = shopDTO; _totalProducts = new List <ProductDTO>(); foreach (ProductListDTO pl in _shopDTO.ProductLists) { foreach (ProductDTO p in pl.Products) { _totalProducts.Add(p); } } }
public static ShopDTO ConvertToDTO(DataRow dr) { ShopDTO sp = new ShopDTO(); sp.MaHoa = dr["MaHoa"].ToString(); sp.TenHoa = dr["TenHoa"].ToString(); sp.GiaTien = Convert.ToInt32(dr["GiaTien"]); sp.SoLuongTonKho = Convert.ToInt32(dr["SoLuongTonKho"]); sp.MaLoaiHoa = dr["MaLoaiHoa"].ToString(); sp.TrangThai = Convert.ToBoolean(dr["TrangThai"]); sp.AnhMinhHoa = dr["AnhMinhHoa"].ToString(); return(sp); }
private void CreateShop(ShopDTO ShopDto) { var newUserShop = new UserShop { ActionDate = DateTime.Now, Dislike = false, Like = true, ShopId = ShopDto.Id, UserId = ShopDto.UserId }; _context.UserShops.Add(newUserShop); }
public async Task <IActionResult> Put([FromBody] ShopDTO value) { try { await _iEFShopService.UpdateShops(value); return(StatusCode(204)); } catch { return(StatusCode(404)); } }
public void CreateShop(ShopDTO shopDto) { if (shopDto == null) { throw new ValidationException("There is no such shop", ""); } var mapper = new MapperConfiguration(cfg => cfg.CreateMap <ShopDTO, Shop>()).CreateMapper(); var shop = mapper.Map <ShopDTO, Shop>(shopDto); Database.Shops.Create(shop); Database.Save(); }
public static bool ToShopDTO(Shop input, ShopDTO output) { if (input == null) { return(false); } output.MapNpcId = input.MapNpcId; output.MenuType = input.MenuType; output.Name = input.Name; output.ShopId = input.ShopId; output.ShopType = input.ShopType; return(true); }
/// <summary> /// Convert Shop into ShopDTO. /// </summary> /// <param name="shop">Shop object.</param> /// <returns>ShopDTO object.</returns> public ShopDTO ConvertToDTO(Shop shop) { var i = new ShopDTO { ShopName = shop.ShopName, CardNumber = shop.CardNumber, ProductLists = ConvertToDTO(shop.ProductLists), AddressId = shop.AddressId, Address = ConvertToDTO(shop.Address), }; return(i); }
public IEnumerable <ShopDTO> LoadAll() { using (OpenNosContext context = DataAccessHelper.CreateContext()) { List <ShopDTO> result = new List <ShopDTO>(); foreach (Shop entity in context.Shop.AsNoTracking()) { ShopDTO dto = new ShopDTO(); Mapper.Mappers.ShopMapper.ToShopDTO(entity, dto); result.Add(dto); } return(result); } }
/// <summary> /// Converts this instance of <see cref="Shop"/> to an instance of <see cref="ShopDTO"/>. /// </summary> /// <param name="entity"><see cref="Shop"/> to convert.</param> public static ShopDTO ToDTO(this Shop entity) { if (entity == null) { return(null); } var dto = new ShopDTO(); dto.ShopId = entity.ShopId; dto.Name = entity.Name; dto.ShortName = entity.ShortName; dto.ShopTypeId = entity.ShopTypeId; dto.ShopClassId = entity.ShopClassId; dto.LocationId = entity.LocationId; dto.Address = entity.Address; dto.CityId = entity.CityId; dto.StateId = entity.StateId; dto.CountryId = entity.CountryId; dto.ZoneId = entity.ZoneId; dto.RouteId = entity.RouteId; dto.Active = entity.Active; dto.DistributorId = entity.DistributorId; dto.ContactPerson = entity.ContactPerson; dto.ContactNo = entity.ContactNo; dto.CreatedDate = entity.CreatedDate; dto.ModifiedDate = entity.ModifiedDate; dto.CreatedBy = entity.CreatedBy; dto.DistrictId = entity.DistrictId; dto.MobileNo = entity.MobileNo; dto.Email = entity.Email; dto.PINCode = entity.PINCode; dto.TINNo = entity.TINNo; dto.CSTNo = entity.CSTNo; dto.ThirdPartyShopCode = entity.ThirdPartyShopCode; dto.CustomerGroupId = entity.CustomerGroupId; dto.CreditLimit = entity.CreditLimit; dto.DailyActive = entity.DailyActive; dto.DoorNo = entity.DoorNo; dto.StreetName = entity.StreetName; dto.ShopLatitude = entity.ShopLatitude; dto.ShopLongitude = entity.ShopLongitude; dto.TransporterId = entity.TransporterId; dto.CreditStatus = entity.CreditStatus; entity.OnDTO(dto); return(dto); }