示例#1
0
        public IActionResult CreateOrderedFood([FromBody] OrderedFoodForCreationDto orderedFoodForCreationDto)
        {
            var orderError = "Please ensure your entered data is correct";

            OrderedFood orderedFood = new OrderedFood();

            if (orderedFoodForCreationDto == null)
            {
                return(BadRequest(orderError));
            }


            orderedFood.FoodId        = orderedFoodForCreationDto.FoodId;
            orderedFood.OrderId       = orderedFoodForCreationDto.OrderId;
            orderedFood.CreatedAtDate = DateTime.Now;

            if (orderedFood.CreatedAtDate == null)
            {
                return(StatusCode(500, "The date is invalid"));
            }
            orderedFood.UpdatedAtDate = orderedFood.CreatedAtDate;

            _orderedFoodRepository.AddOrderedFood(orderedFood);

            if (!_orderedFoodRepository.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

            return(Ok(orderedFood));
        }
示例#2
0
        public IActionResult CreateDriver([FromBody] DriverForCreationDto driverInfo)
        {
            var    driverError = "Please look at your data and make sure it's not empty, incorrect, or has values that are the same!";
            Driver driver      = new Driver();

            if (driverInfo == null)
            {
                return(BadRequest(driverError));
            }


            driver.Name = driverInfo.Name;
            if (driverInfo.Name == null)
            {
                return(StatusCode(500, "The name is invalid or too long!"));
            }
            driver.CreatedAtDate = DateTime.Now;
            driver.UpdatedAtDate = driver.CreatedAtDate;
            if (!_driverInfoRepository.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

            return(Ok(driver));
        }
示例#3
0
        public IActionResult CreateFood([FromBody] FoodForCreationDto foodInfo)
        {
            var foodError = "Please look at your data and make sure it's not empty, incorrect, or has values that are the same!";

            Food food = new Food();


            if (foodInfo == null)
            {
                return(BadRequest(foodError));
            }

            food.Name = foodInfo.Name;
            if (food.Name == null || food.Name.Length > 10)
            {
                return(StatusCode(500, "Sorry, the name is too long, or you forgot to enter it"));
            }


            food.Description = foodInfo.Description;
            if (food.Description == null || food.Name.Length > 100)
            {
                return(StatusCode(500, "Sorry, the description is too long, or you forgot to enter it"));
            }

            food.RestaurantId = foodInfo.RestaurantId;


            food.Cost = foodInfo.Cost;
            if (food.Cost == null || food.Cost.Equals(0))
            {
                return(StatusCode(500, "Sorry, the cost cannot be 0"));
            }


            food.CreatedAtDate = DateTime.Now;
            food.UpdatedAtDate = food.CreatedAtDate;


            _foodInfoRepository.AddFood(food);

            if (!_foodInfoRepository.Save())
            {
                return(StatusCode(500, "Something went wrong during the request..."));
            }


            return(Ok(food));
        }
示例#4
0
        public IActionResult CreateCustomer([FromBody] CustomerForCreationDto customerInfo)
        {
            var      customerError = "Please look at your data and make sure it's not empty, incorrect, or has values that are the same!";
            Customer customer      = new Customer();

            if (customerInfo == null)
            {
                return(BadRequest(customerError));
            }

            if (customerInfo.Name == customerInfo.Adress || customerInfo.Name == customerInfo.MobileNr || customerInfo.MobileNr == customerInfo.Adress)
            {
                return(BadRequest(customerError));
            }

            // Convert CustomerForCreationDto to Customer entity
            customer.Adress = customerInfo.Adress;
            if (customer.Adress.Length > 50)
            {
                return(StatusCode(500, "Your adress is too long. Please make sure it's less than 50 characters!"));
            }

            customer.Name = customerInfo.Name;
            if (customer.Name.Length > 50)
            {
                return(StatusCode(500, "Your name is too long. Please ensure it's less than 50 characters long!"));
            }



            customer.CreatedAtDate = DateTime.Now;
            customer.UpdatedAtDate = customer.CreatedAtDate;



            _customerInfoRepository.AddCustomer(customer);

            if (!_customerInfoRepository.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

            return(Ok(customer));
        }
示例#5
0
        public IActionResult CreateRestaurant([FromBody] RestaurantForCreationDto restaurantInfo)
        {
            var        restaurantError = "Please look at the data and make sure it's not empty, incorrect, or has values that are the same!";
            Restaurant restaurant      = new Restaurant();

            if (restaurantInfo == null)
            {
                return(BadRequest(restaurantError));
            }


            restaurant.Name = restaurantInfo.Name;
            if (restaurantInfo.Name == null || restaurantInfo.Name.Length > 50)
            {
                return(StatusCode(500, "The name is either null or too long"));
            }


            restaurant.Adress = restaurantInfo.Adress;
            if (restaurantInfo.Adress == null || restaurantInfo.Adress.Length > 50)
            {
                return(StatusCode(500, "The adress is null or too long"));
            }



            restaurant.foods = restaurantInfo.foods;

            restaurant.CreatedAtDate = DateTime.Now;
            restaurant.UpdatedAtDate = DateTime.Now;



            _restaurantInfoRepository.AddRestaurant(restaurant);

            if (!_restaurantInfoRepository.Save())
            {
                return(StatusCode(500, "SOmething wEnT WrOnG wHilE HanDlIng yOuR ReQUesT."));
            }

            return(Ok(restaurant));
        }
示例#6
0
        public IActionResult CreateOrder([FromBody] OrderForCreationDto orderInfo)
        {
            var   orderError = "Please ensure your data is correct!";
            Order order      = new Order();

            if (orderInfo == null)
            {
                return(BadRequest(orderError));
            }


            order.CustomerId   = orderInfo.CustomerId;
            order.DriverId     = orderInfo.DriverId;
            order.RestaurantId = orderInfo.RestaurantId;



            order.TotalCost = orderInfo.Cost;

            if (order.TotalCost < 0)
            {
                return(StatusCode(500, "Cost can't be less than 0!"));
            }
            order.CreatedAtDate = DateTime.Now;
            order.UpdatedAtDate = order.CreatedAtDate;


            _orderInfoRepository.AddOrder(order);

            if (!_orderInfoRepository.Save())
            {
                return(StatusCode(500, "Something went wrong..."));
            }


            return(Ok(order));
        }
        public ActionResult EditInfo(InfoEditInfoVM model)
        {
            UnitOfWork unitOfWork = new UnitOfWork();
            InfoRepository infoRepository = new InfoRepository(unitOfWork);
            Info info = new Info();

            if (infoRepository.GetAll(filter: x => x.Title == model.Title && x.ID != model.ID).FirstOrDefault() != null)
            {
                ModelState.AddModelError("Title", "Article with same name exist");
            }

            model.Title = model.Title.Trim();

            string message = "Successfully created ";

            if (model.ID > 0)
            {
                info = infoRepository.GetByID(model.ID);
                message = "Successfully edited ";
                if (info.Title != model.Title)
                {
                    string filesLocalPath = "~/Content/Files/" + model.Title;
                    if (Directory.Exists(HostingEnvironment.MapPath(filesLocalPath + info.Title)))
                    {
                        Directory.Move(HostingEnvironment.MapPath(filesLocalPath + info.Title),
                                       HostingEnvironment.MapPath(filesLocalPath + model.Title));
                    }
                }
            }

            model.Content = model.Content.Trim();

            info.Content = model.Content;
            info.Title = model.Title;

            infoRepository.Save(info);

            InfoImageRepository infoImageRepository = new InfoImageRepository(unitOfWork);

            HttpFileCollection UploadedFiles = System.Web.HttpContext.Current.Request.Files;

            string filePath = "~/Content/Files/" + model.Title + "/";

            Regex imageRegex = new Regex(ConfigurationManager.AppSettings["ImageRestriction"]);
            Regex fileRegex = new Regex(ConfigurationManager.AppSettings["FileRestriction"]);

            for (int i = 0; i < UploadedFiles.Count; i++)
            {
                if (imageRegex.Match(UploadedFiles[i].FileName).Success)
                {
                    InfoImage infoImage = new InfoImage();

                    infoImage.Name = UploadedFiles[i].FileName;

                    if (infoImageRepository.GetAll(filter: x => x.Name == infoImage.Name && x.InfoID == info.ID).FirstOrDefault() == null)
                    {
                        info.Images = info.Images == null ? info.Images = new List<InfoImage>() : info.Images;
                        info.Images.Add(infoImage);

                        //Create  folder
                        if (!Directory.Exists(HostingEnvironment.MapPath(filePath)))
                            Directory.CreateDirectory(HostingEnvironment.MapPath(filePath));

                        UploadedFiles[i].SaveAs(HostingEnvironment.MapPath(filePath) + UploadedFiles[i].FileName);
                    }
                }
                else if (fileRegex.Match(UploadedFiles[i].FileName).Success)
                {
                    var file = UploadedFiles[i];

                    //Create  folder
                    if (!Directory.Exists(HostingEnvironment.MapPath(filePath)))
                        Directory.CreateDirectory(HostingEnvironment.MapPath(filePath));

                    //If other file is uploaded we delete the old
                    if (info.FileName != null && System.IO.File.Exists(HostingEnvironment.MapPath(filePath + info.FileName)) && file.FileName != info.FileName)
                        System.IO.File.Delete(HostingEnvironment.MapPath(filePath + info.FileName));

                    info.FileName = file.FileName;

                    file.SaveAs(HostingEnvironment.MapPath(filePath) + file.FileName);
                }
            }

            infoRepository.Save(info);
            unitOfWork.Commit();

            AddRemoveKeywords(model.KeywordsInput, info.ID);

            return RedirectToAction("InfoPage", "Info");
        }
示例#8
0
        public bool Save(StudentInfoModel category)
        {
            var save = _infoRepository.Save(category);

            return(save);
        }