private IOffer buy2MilksGet20percentOffOffer()
        {
            Dairy  dairy = new Dairy("Test", new decimal(0.0), new DateTime());
            IOffer offer = new Offer(2, 0, 20, dairy.GetType());

            return(offer);
        }
示例#2
0
        public Dairy GetDairy(DateTime date)
        {
            Dairy dairy = new Dairy();

            dairy.SubjectsDairy = new List <SubjectDiary>();
            try
            {
                query           = "GetStudentDairy";
                cmd             = new SqlCommand(query, con);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@studentId", System.Data.SqlDbType.Int)).Value = id;
                cmd.Parameters.Add(new SqlParameter("@date", System.Data.SqlDbType.Date)).Value     = date;
                con.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    dairy.SubjectsDairy.Add(new SubjectDiary()
                    {
                        Content = (string)reader[0],
                        Subject = new Subject((int)reader[1], con.ConnectionString)
                    });
                }
                dairy.Date = date;
                con.Close();
            }
            catch (SqlException ex)
            {
                Exception e = new Exception("Error Occured in Database processing. CodeIndex:157", ex);
                throw e;
            }
            return(dairy);
        }
示例#3
0
        public IActionResult CreateDairy([FromForm] DairyForCreateDto dairyForCreate, int userId)
        {
            var uId = Convert.ToInt32(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            if (userId != uId)
            {
                return(Unauthorized());
            }


            var user = _userRepository.GetUser(uId);

            var file = dairyForCreate.File;
            //this is the reponse that will be recvied from cloudinary
            var uploadResult = new ImageUploadResult();

            if (file.Length > 0)
            {
                using (var stream = file.OpenReadStream())
                {
                    var uploadParams = new ImageUploadParams()
                    {
                        File = new FileDescription(file.Name, stream),
                        //3shan n3dl fl sora lw hya akbr mn 500 s3tha hy2os mn 3la el 7rof
                        //we yrkz 3lael wsh
                        Transformation = new Transformation().Width(500).Height(500).Crop("fill").Gravity("face")
                    };
                    //hna el sora et3mlha upload kda
                    uploadResult = _cloudinary.Upload(uploadParams);
                }
            }
            //bn3ml set ll url bta3 el sora bl dto bta3y elly hyro7 el db
            dairyForCreate.Url      = uploadResult.Url.ToString();
            dairyForCreate.PublicId = uploadResult.PublicId;


            Dairy dairy = new Dairy
            {
                UserId = userId,
                Date   = dairyForCreate.Date,
                Text   = dairyForCreate.Text,
                Time   = dairyForCreate.Time,
            };

            Photo photo = new Photo
            {
                DairyId   = dairyForCreate.DairyId,
                DataAdded = DateTime.Now,
                PublicId  = dairyForCreate.PublicId,
                Url       = dairyForCreate.Url
            };

            User newUser = new User {
                UserId = userId
            };


            _dairyRepository.CreateDairy(dairy, photo, newUser);
            return(Ok(dairyForCreate));
        }
示例#4
0
 public bool PostUser([FromBody] Dairy dairy)
 {
     try
     {
         return(BL.DairyLogic.AddDairy(dairy));
     }
     catch
     {
         return(false);
     }
 }
示例#5
0
 public void EventSourcingStorage(DatabaseType dbType, string connection)
 {
     if (String.IsNullOrEmpty(connection))
     {
         throw new ArgumentNullException(nameof(connection));
     }
     eventStorage = new Dairy(dbType, connection, persona);
     salida.SinSalida();
     eventStorage.RecuperarEstado(this);
     salida.ConSalida();
 }
示例#6
0
 public bool UpdateUser(Dairy dairy)
 {
     try
     {
         BL.DairyLogic.UpdateDairy(dairy);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
示例#7
0
        public static List <Dairy> AllDaries(int id)
        {
            try
            {
                //List<DAL.Dairy> l = new List<DAL.Dairy>();
                List <DAL.Dairy> l = db.Dairy.Where(d => d.UserId == id).ToList();

                return(Dairy.GetListDairyDTO(l));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
示例#8
0
        public static void UpdateDairy(Dairy dairy)
        {
            try
            {
                var dairyDb = db.Dairy.FirstOrDefault(p => p.DairyId == dairy.DairyId);
                dairy.RoomId        = dairy.RoomId;
                dairyDb.start       = dairy.start;
                dairyDb.end         = dairy.end;
                dairyDb.Description = dairy.Description;
                dairyDb.TypeMeeting = dairy.TypeMeeting;
                dairyDb.UserId      = dairy.UserId;
                dairyDb.title       = dairy.title;

                db.SaveChanges();
            }
            catch (Exception)
            {
            }
        }
示例#9
0
        public static bool AddDairy(Dairy dairy)
        {
            try
            {
                var r = DTO.NewFolder1.Dairy.GetDairy(dairy);

                r.Rooms        = db.Rooms.FirstOrDefault(p => p.RoomId == r.RoomId);
                r.color        = "g";
                r.Rooms1       = db.Rooms.FirstOrDefault(p => p.RoomId == r.RoomId);
                r.users        = db.users.FirstOrDefault(x => x.UserId == r.UserId);
                r.TypeMeeting1 = db.TypeMeeting.FirstOrDefault(x => x.MeetingId == r.TypeMeeting);
                db.Dairy.Add(r);
                db.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
示例#10
0
        public void CreateDairy(Dairy dairyForCreateDto, Photo photo, User user)
        {
            Dairy dairy = new Dairy
            {
                DairyId = dairyForCreateDto.DairyId,
                Date    = dairyForCreateDto.Date,
                Text    = dairyForCreateDto.Text,
                Time    = dairyForCreateDto.Time,
                UserId  = dairyForCreateDto.UserId
            };
            User newUser = new User
            {
                UserId = user.UserId
            };

            dairy.Photos.Add(photo);
            _context.Dairies.Add(dairy);
            newUser.Dairies.Add(dairy);
            _context.SaveChanges();
        }
示例#11
0
 public static DairyDTO DairyToDTO(Dairy dairy)
 {
     return(new DairyDTO()
     {
         Id = dairy.Id,
         GroupId = dairy.GroupId,
         Num = dairy.Num,
         CalculateHours = dairy.CalculateHours,
         Cause = dairy.Cause,
         FromDate = DateToDTO(dairy.FromDate),
         Hour = dairy.Hour,
         IsGrouped = dairy.IsGrouped,
         OccasionId = dairy.OccasionId,
         Reforma = dairy.Reforma,
         RoomId = dairy.RoomId,
         SubjectId = dairy.SubjectId,
         TeacherId = dairy.TeacherId,
         ToDate = DateToDTO(dairy.ToDate),
         TypeId = dairy.TypeId,
         //Classes = dairy.Classes.Select(c => c.Num).ToList()
     });
 }
        private IBasket createBasket(int numberOfMilks, int numberOfVegetables)
        {
            Dairy     milk    = new Dairy("MilkOne", new decimal(30.0), new DateTime());
            Vegetable lettuce = new Vegetable("LettuceOne", new decimal(20.0));

            List <IProduct> products = new List <IProduct>();


            for (int i = 0; i < numberOfMilks; i++)
            {
                products.Add(milk);
            }

            for (int i = 0; i < numberOfVegetables; i++)
            {
                products.Add(lettuce);
            }

            IBasket basket = new Basket(products);

            return(basket);
        }
        // HELPERS
        private IBasket createBasketWithUniqueProducts()
        {
            Dairy milk  = new Dairy("MilkOne", new decimal(30.0), new DateTime());
            Dairy milk1 = new Dairy("MilkOne", new decimal(30.0), new DateTime());
            Dairy milk2 = new Dairy("MilkOne", new decimal(30.0), new DateTime());
            Dairy milk3 = new Dairy("MilkOne", new decimal(30.0), new DateTime());
            Dairy milk4 = new Dairy("MilkOne", new decimal(30.0), new DateTime());

            Vegetable lettuce = new Vegetable("LettuceOne", new decimal(20.0));
            Vegetable cabbage = new Vegetable("LettuceOne", new decimal(20.0));

            List <IProduct> products = new List <IProduct>();

            products.Add(milk);
            products.Add(milk1);
            products.Add(milk2);
            products.Add(milk3);
            products.Add(milk4);
            products.Add(lettuce);
            products.Add(cabbage);
            IBasket basket = new Basket(products);

            return(basket);
        }
示例#14
0
        //[Authorize]
        public async Task <IActionResult> PostFood([FromBody] List <TotalFood> food)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = await _userManager.GetUserAsync(User);

            var usr = _userManager.GetUserId(User);

            foreach (var item in food)
            {
                for (int i = 0; i <= item.Quantity; i++)
                {
                    user.TotalFood.Add(item);
                    item.UserName  = user.UserName;
                    item.TimeStamp = DateTime.UtcNow;
                    item.PickedUp  = false;
                    item.Available = true;
                    item.Selected  = false;
                    _context.TotalFood.Add(item);

                    if (item.Type == "Box Food")
                    {
                        var boxFood = new BoxFood();
                        boxFood.Owner     = user;
                        boxFood.UserName  = user.UserName;
                        boxFood.TimeStamp = DateTime.UtcNow;
                        boxFood.PickedUp  = false;
                        boxFood.Available = true;
                        boxFood.Selected  = false;
                        _context.BoxFood.Add(boxFood);
                    }
                    else if (item.Type == "Can Food")
                    {
                        var canFood = new CanFood();
                        canFood.Owner     = user;
                        canFood.UserName  = user.UserName;
                        canFood.TimeStamp = DateTime.UtcNow;
                        canFood.PickedUp  = false;
                        canFood.Available = true;
                        canFood.Selected  = false;
                        _context.CanFood.Add(canFood);
                    }
                    else if (item.Type == "Fruit")
                    {
                        var fruit = new Fruit();
                        fruit.Owner     = user;
                        fruit.UserName  = user.UserName;
                        fruit.TimeStamp = DateTime.UtcNow;
                        fruit.PickedUp  = false;
                        fruit.Available = true;
                        fruit.Selected  = false;
                        _context.Fruit.Add(fruit);
                    }
                    else if (item.Type == "Meat")
                    {
                        var meat = new Meat();
                        meat.Owner     = user;
                        meat.UserName  = user.UserName;
                        meat.TimeStamp = DateTime.UtcNow;
                        meat.PickedUp  = false;
                        meat.Available = true;
                        meat.Selected  = false;
                        _context.Meat.Add(meat);
                    }
                    else if (item.Type == "Vegetables")
                    {
                        var veggies = new Vegetables();
                        veggies.Owner     = user;
                        veggies.UserName  = user.UserName;
                        veggies.TimeStamp = DateTime.UtcNow;
                        veggies.PickedUp  = false;
                        veggies.Available = true;
                        veggies.Selected  = false;
                        _context.Vegetables.Add(veggies);
                    }
                    else if (item.Type == "Dairy")
                    {
                        var dairy = new Dairy();
                        dairy.Owner     = user;
                        dairy.UserName  = user.UserName;
                        dairy.TimeStamp = DateTime.UtcNow;
                        dairy.PickedUp  = false;
                        dairy.Available = true;
                        dairy.Selected  = false;
                        _context.Dairy.Add(dairy);
                    }
                    else if (item.Type == "Drinks")
                    {
                        var drink = new Drinks();
                        drink.Owner     = user;
                        drink.UserName  = user.UserName;
                        drink.TimeStamp = DateTime.UtcNow;
                        drink.PickedUp  = false;
                        drink.Available = true;
                        drink.Selected  = false;
                        _context.Drinks.Add(drink);
                    }
                }

                item.Quantity = 0;
            }

            await _context.SaveChangesAsync();

            return(Ok(food));
        }
示例#15
0
 public DairyCreator(Dairy newDairy)
 {
     _baseDairy = newDairy;
 }