Esempio n. 1
0
        public void addProperty(int id, int surface, int rentalPrice)
        {
            CommercialSpace property = new CommercialSpace(id, surface, rentalPrice);

            this.val.validateProperty(property);
            repo.addElement(property);
        }
 public void EditCommercialSpace(CommercialSpace space)
 {
     if (space != null)
     {
         dbContext.Attach(space);
         dbContext.Entry(space).State = EntityState.Modified;
     }
 }
 public CommercialSpace AddCommercialSpace(CommercialSpace space)
 {
     dbContext.CommercialSpaces.Add(space);
     return(space);
 }
Esempio n. 4
0
        public void readFromFile(String fileName)
        {
            StreamReader sr = new StreamReader(fileName);
            String       line;

            String[] tokens;
            errorCounter = 0;

            List <Transaction> newList = new List <Transaction>();

            try
            {
                while ((line = sr.ReadLine()) != null)
                {
                    tokens = line.Split(new String[] { ";" }, StringSplitOptions.None);

                    if ("Flat".Equals(tokens[0]))
                    {
                        if (tokens.Length != 6)
                        {
                            throw new MyException("Wrong number of arguments!");
                        }
                        Flat        flat  = new Flat(Convert.ToInt32(tokens[2]), tokens[3], Convert.ToInt32(tokens[1]));
                        Transaction trans = new Transaction(flat, Convert.ToInt32(tokens[4]), Convert.ToInt32(tokens[5]));
                        val.validateTransaction(trans);
                        newList.Add(trans);
                    }
                    else if ("House".Equals(tokens[0]))
                    {
                        if (tokens.Length != 7)
                        {
                            throw new MyException("Wrong number of arguments!");
                        }
                        House       house = new House(Convert.ToInt32(tokens[3]), tokens[4], Convert.ToInt32(tokens[2]), Convert.ToInt32(tokens[1]));
                        Transaction trans = new Transaction(house, Convert.ToInt32(tokens[5]), Convert.ToInt32(tokens[6]));
                        val.validateTransaction(trans);
                        newList.Add(trans);
                    }
                    else if ("CommercialSpace".Equals(tokens[0]))
                    {
                        if (tokens.Length != 5)
                        {
                            throw new MyException("Wrong number of arguments!");
                        }
                        CommercialSpace commercialSpace = new CommercialSpace(Convert.ToInt32(tokens[1]), tokens[2]);
                        Transaction     trans           = new Transaction(commercialSpace, Convert.ToInt32(tokens[3]), Convert.ToInt32(tokens[4]));
                        val.validateTransaction(trans);
                        newList.Add(trans);
                    }
                    else
                    {
                        throw new MyException("Error reading from file!");
                    }
                }
            }
            catch (FormatException ex)
            {
                errorCounter++;
                throw new MyException(ex.Message);
            }
            catch (MyException ex)
            {
                errorCounter++;
                throw new MyException(ex.getMessage());
            }


            this.repo.replaceContent(newList);
            sr.Close();
        }
Esempio n. 5
0
        public async Task <IActionResult> AddCommercialSpace(AddCommercialSpaceViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await userManager.GetUserAsync(HttpContext.User);

                var cs = new CommercialSpace
                {
                    Address          = model.Address,
                    Advance          = model.Advance,
                    City             = model.City,
                    ConstructionYear = model.ConstructionYear,
                    FullDescription  = model.Description,
                    Price            = model.Price,
                    SquareMetrage    = model.SquareMetrage,
                    MainPageDisplay  = model.MainPageDisplay,
                    Name             = model.Name,
                    NumberOfRooms    = model.NumberOfRooms,
                    PropertyType     = PropertyType.Lokal_użytkowy,
                    LocalType        = model.Type,
                    Floor            = model.Floor,
                    OwnerID          = user.Id,
                    Images           = new List <Photo>(),
                    AgencyName       = model.AgencyName
                };

                Advertisement adv = new Advertisement
                {
                    PropertyType    = PropertyType.Lokal_użytkowy,
                    DateAdded       = DateTime.Now,
                    EndDate         = adManager.SetExpirationDate(model.AdvLength),
                    Name            = model.Name,
                    User            = user,
                    CommercialSpace = cs
                };
                string mainName;
                string uploadsDirectory = Path.Combine(hostingEnvironment.WebRootPath, "images");
                if (model.MainImage != null)
                {
                    mainName = adManager.ReturnUniqueName(model.MainImage);
                    var photo = new Photo
                    {
                        PhotoName = mainName,
                        PhotoPath = uploadsDirectory,
                        //If using HasOne (OneToOne Relationship) instead of Owns One(OwnedType)
                        //CommercialSpacePrincipal = cs
                    };
                    adManager.UploadPhoto(model.MainImage, uploadsDirectory, mainName);
                    cs.MainImageName = photo.PhotoName;
                }
                List <string> photoNames = new List <string>();
                if (model.Images != null && model.Images.Count > 0)
                {
                    var galleryPath = Path.Combine(hostingEnvironment.WebRootPath, "images", "Gallery_cs_id_" + $"{model.Name}");
                    if (!Directory.Exists(galleryPath))
                    {
                        Directory.CreateDirectory(galleryPath);
                    }
                    foreach (var photo in model.Images)
                    {
                        string name = adManager.ReturnUniqueName(photo);
                        photoNames.Add(name);
                        adManager.UploadPhoto(photo, galleryPath, name);
                    }
                    foreach (var photoName in photoNames)
                    {
                        cs.Images.Add(new Photo {
                            PhotoName = photoName, PhotoPath = galleryPath                       /*CommercialSpacesPrincipal = cs */
                        });
                    }
                }
                adv.CommercialSpace = cs;
                unit.AdvertismentRepository.AddAdvertisement(adv);
                unit.SaveData();
                if (model.MainPageDisplay == true)
                {
                    return(RedirectToAction("Promote", "Advertisements", adv));
                }
            }
            return(RedirectToAction("Success", "Customers"));
        }