public ActionResult AddToCart(string id)
        {
            DAL.RestaurantMenu    restaurantMenu = menuModel.find(int.Parse(DataSecurityTripleDES.GetPlainText(id)));
            RestaurantMenuCartDTO thisMenuDTO    = EntityDTOHelper.GetEntityDTO <RestaurantMenu, RestaurantMenuCartDTO>(restaurantMenu);

            DAL.Restaurant restaurant = db.Restaurant.Find(restaurantMenu.OwnerId);

            thisMenuDTO.ServiceOwnerName = restaurant.Name;
            thisMenuDTO.ServiceOwnerId   = DataSecurityTripleDES.GetEncryptedText(restaurant.Id);
            thisMenuDTO.ServiceOwnerType = DataSecurityTripleDES.GetEncryptedText((int)OwnerTypeEnum.ServiceProvider);

            DAL.Address address = db.Address.Find(restaurant.AddressId);
            if (address != null)
            {
                AddressDTO addressDTO = EntityDTOHelper.GetEntityDTO <DAL.Address, AddressDTO>(address);
                thisMenuDTO.ServiceOwnerAddressDetail = addressDTO.GetAddressString(true);
            }

            if (thisMenuDTO != null)
            {
                thisMenuDTO.Quantity = 1;

                CraveatsCart craveatsCart = (Session["cart"] == null) ? new CraveatsCart(SessionManager.GetContextSessionLoggedUserID()) : (Session["cart"] as CraveatsCart);
                craveatsCart.AddToCart(thisMenuDTO);

                Session["cart"] = craveatsCart;
            }

            return(RedirectToAction("Index"));
        }
Exemple #2
0
        public DAL.Address saveInDB()
        {
            DAL.Address entity = null;
            // Create, if not existant
            if (this.id == 0)
            {
                entity = MainClass.Instance.db.Address.Add(new DAL.Address()
                {
                    country    = this.country,
                    location   = this.location,
                    name       = this.name,
                    postCode   = this.postalCode,
                    streetName = this.streetName
                });
                MainClass.Instance.db.SaveChanges();
                this.id = entity.id;
            }
            else
            {
                entity = MainClass.Instance.db.Address.Where(v => v.id == this.id).FirstOrDefault();

                if (entity == null)
                {
                    return(null);
                }

                entity.country    = this.country;
                entity.location   = this.location;
                entity.name       = this.name;
                entity.postCode   = this.postalCode;
                entity.streetName = this.streetName;
                MainClass.Instance.db.SaveChanges();
            }
            return(entity);
        }
Exemple #3
0
        public static void SaveInstallmentRequest(InstallmentRequestViewModel model, string UserId)
        {
            LoanAndRepayEntities entities           = new LoanAndRepayEntities();
            InstallmentRequest   installmentRequest = new InstallmentRequest();

            DAL.Address address = new DAL.Address();

            //First saves the installment request information in the installment table
            installmentRequest.UserId         = UserId;
            installmentRequest.Company        = model.Company;
            installmentRequest.FirstName      = model.FirstName;
            installmentRequest.LastName       = model.LastName;
            installmentRequest.Email          = model.Email;
            installmentRequest.Age            = model.Age;
            installmentRequest.Phone          = model.Phone;
            installmentRequest.Amount         = model.Amount;
            installmentRequest.PayWithIn      = model.PayWithIn;
            installmentRequest.MonthlyPayment = model.MonthlyPayment;
            installmentRequest.Status         = model.Status;
            entities.InstallmentRequests.Add(installmentRequest);
            entities.SaveChanges();
            var checkExistingInstallment = entities.InstallmentRequests.Where(x => x.Company == model.Company && x.Email == model.Email).FirstOrDefault();

            //Then saves the installment request address in the address table
            address.StreetName  = model.StreetName;
            address.HouseNumber = model.HouseNumber;
            address.CityName    = model.CityName;
            address.PostCode    = model.PostCode;

            address.InstallmentId = checkExistingInstallment.Id;
            entities.Addresses.Add(address);
            entities.SaveChanges();
        }
Exemple #4
0
        public static void SaveCompanyInfo(RegisterCompanyBindingModel registerCompanyModel, string userId)
        {
            LoanAndRepayEntities database = new LoanAndRepayEntities();

            CompanyInfo companyInfo = new CompanyInfo();

            DAL.Address address = new DAL.Address();
            if (companyInfo != null)
            {
                //First saves the company information in the company table
                companyInfo.UserId      = userId;
                companyInfo.CompanyName = registerCompanyModel.CompanyName;
                companyInfo.CVR         = registerCompanyModel.CVR;
                companyInfo.Email       = registerCompanyModel.Email;
                companyInfo.Phone       = registerCompanyModel.Phone;
                database.CompanyInfoes.Add(companyInfo);

                //Then saves the company address in the address table
                address.StreetName  = registerCompanyModel.StreetName;
                address.HouseNumber = registerCompanyModel.HouseNumber;
                address.CityName    = registerCompanyModel.CityName;
                address.PostCode    = registerCompanyModel.PostCode;
                address.UserId      = userId;
                database.Addresses.Add(address);
                database.SaveChanges();
            }
        }
Exemple #5
0
        public ActionResult PartnerRestaurant(PartnerRestaurantViewModel model)
        {
            if (Session != null && Session.Contents != null)
            {
                AuthenticatedUserInfo authenticatedUserInfo = Session["loggeduser"] as AuthenticatedUserInfo;

                if (authenticatedUserInfo != null)
                {
                    UserDTO userDTO = EntityDTOHelper.GetEntityDTO <DAL.User, UserDTO>(new CEUserManager().FindById(
                                                                                           int.Parse(DataSecurityTripleDES.GetPlainText(authenticatedUserInfo.UserId))));

                    PartnerRestaurantViewModel partnerRestaurantViewModel = null;

                    if (((Common.UserTypeEnum)userDTO.UserTypeFlag).HasFlag(Common.UserTypeEnum.PartnerRestaurant))
                    {
                        partnerRestaurantViewModel = new PartnerRestaurantViewModel()
                        {
                            Id            = userDTO.Id,
                            ContactNumber = userDTO.ContactNumber,
                            Email         = userDTO.EmailAddress,
                            FirstName     = userDTO.FirstName,
                            Surname       = userDTO.Surname,
                            Role          = Common.UserTypeEnum.PartnerRestaurant.GetDescription()
                        };
                    }

                    if ((userDTO.AddressId ?? "").Length > 0)
                    {
                        DataProvider dataProvider = new DataProvider();

                        DAL.Address anAddress = dataProvider.FindAddressById(
                            int.Parse(DataSecurityTripleDES.GetPlainText(userDTO.AddressId)));

                        AddressViewModel addressViewModel = EntityDTOHelper.GetEntityDTO <DAL.Address, AddressViewModel>(anAddress);

                        if (anAddress != null)
                        {
                            DAL.Region region = dataProvider.FindRegionById(anAddress.RegionId ?? 0);

                            if (region != null)
                            {
                                addressViewModel.RegionAlias = region.RegionAlias;
                                addressViewModel.RegionId    = DataSecurityTripleDES.GetEncryptedText(region.Id);
                            }

                            partnerRestaurantViewModel.Addresses = new List <AddressViewModel>()
                            {
                                addressViewModel
                            };
                        }
                    }

                    return(View("PartnerRestaurant", partnerRestaurantViewModel));
                }
            }

            return(View("Error"));
        }
Exemple #6
0
 public Address(DAL.Address address)
 {
     this.id         = address.id;
     this.name       = address.name ?? throw new ArgumentNullException(nameof(address.name));
     this.streetName = address.streetName ?? throw new ArgumentNullException(nameof(address.streetName));
     this.location   = address.location ?? throw new ArgumentNullException(nameof(address.location));
     this.postalCode = address.postCode ?? throw new ArgumentNullException(nameof(address.postCode));
     this.country    = address.country ?? throw new ArgumentNullException(nameof(address.country));
 }
Exemple #7
0
        public ActionResult EditAddress(AddressViewModel model, string returnUrl)
        {
            SessionManager.RegisterSessionActivity();

            IEnumerable <string> regionAliases = GetAllRegionAliases();

            model.RegionAliases = GenUtil.GetSelectListItems(regionAliases);

            if (ModelState.IsValid)
            {
                DataProvider dataProvider = new DataProvider();

                DAL.Address address = dataProvider.FindAddressById(
                    int.Parse(DataSecurityTripleDES.GetPlainText(model.Id)));

                if (address != null)
                {
                    AddressDTO addressDTO = new AddressDTO()
                    {
                        Id          = model.Id,
                        City        = model.City,
                        Line1       = model.Line1,
                        Line2       = model.Line2,
                        Postcode    = model.Postcode,
                        RegionAlias = model.RegionAlias
                    };

                    using (DAL.CraveatsDbContext c = new DAL.CraveatsDbContext())
                    {
                        addressDTO.RegionId = DataSecurityTripleDES.GetEncryptedText(
                            c.Region.FirstOrDefault(r => r.CountryISO2 == "CA" &&
                                                    r.RegionAlias == addressDTO.RegionAlias).Id);

                        addressDTO.CountryId = DataSecurityTripleDES.GetEncryptedText(
                            c.Country.FirstOrDefault(s => s.ISO2 == "CA").Id);

                        address = c.Address.FirstOrDefault(u => u.Id == address.Id);
                        address = EntityDTOHelper.MapToEntity <AddressDTO, DAL.Address>(addressDTO, address);

                        c.SaveChanges();

                        return(RedirectToAction("ProfileView"));
                    }
                }
            }

            // Something is not right - so render the registration page again,
            // keeping the data user has entered by supplying the model.
            return(View("EditAddress", model));
        }
        internal void SaveDependent(DAL.CustomersDataContext dc, DAL.Customer c, int actionPerformerId)
        {
            DAL.Address dalAddress = null;

            if (this.Id == 0)
            {
                dalAddress = new CustomerManagement.DAL.Address();
                map(dc, this, dalAddress, actionPerformerId);
                dalAddress.Customer = c;
                this.CustomerId = c.Id; // handles the case where the whole graph is saved with one Save() call
                dc.Addresses.InsertOnSubmit(dalAddress);
            }
            else
            {
                dalAddress = dc.Addresses.Where(record => record.Id == this.Id).Single();
                map(dc, this, dalAddress, actionPerformerId);
            }

            dc.SubmitChanges();
            this.Id = dalAddress.Id;
        }
Exemple #9
0
        public ActionResult AddAddress(AddressViewModel model, string returnUrl)
        {
            SessionManager.RegisterSessionActivity();

            IEnumerable <string> regionAliases = GetAllRegionAliases();

            model.RegionAliases = GenUtil.GetSelectListItems(regionAliases);

            if (ModelState.IsValid)
            {
                AuthenticatedUserInfo authenticatedUserInfo = Session["loggeduser"] as AuthenticatedUserInfo;
                if (authenticatedUserInfo != null)
                {
                    int ownerType = model.OwnerType?.Length > 0
                        ? int.Parse(DataSecurityTripleDES.GetPlainText(model.OwnerType))
                        : -1;

                    int ownerId = model.OwnerId?.Length > 0
                        ? int.Parse(DataSecurityTripleDES.GetPlainText(model.OwnerType))
                        : -1;

                    DAL.User addressOwner = null;
                    if (!(ownerType > -1 && ownerId > 0))
                    {
                        addressOwner = new CEUserManager().FindById(
                            int.Parse(DataSecurityTripleDES.GetPlainText(authenticatedUserInfo.UserId)));
                    }

                    DataProvider dataProvider = new DataProvider();
                    AddressDTO   addressDTO   = new AddressDTO()
                    {
                        City        = model.City,
                        Line1       = model.Line1,
                        Line2       = model.Line2,
                        Postcode    = model.Postcode,
                        RegionAlias = model.RegionAlias
                    };

                    if (addressOwner != null && !addressOwner.AddressId.HasValue)
                    {
                        addressDTO.OwnerType = (int)Common.OwnerTypeEnum.User;
                        addressDTO.OwnerId   = authenticatedUserInfo.UserId;

                        using (DAL.CraveatsDbContext c = new DAL.CraveatsDbContext())
                        {
                            addressDTO.RegionId = DataSecurityTripleDES.GetEncryptedText(
                                c.Region.FirstOrDefault(r => r.CountryISO2 == "CA" &&
                                                        r.RegionAlias == addressDTO.RegionAlias).Id);

                            addressDTO.CountryId = DataSecurityTripleDES.GetEncryptedText(
                                c.Country.FirstOrDefault(s => s.ISO2 == "CA").Id);

                            DAL.Address newAddress = EntityDTOHelper.MapToEntity <AddressDTO, DAL.Address>(
                                addressDTO, null, true);
                            newAddress.AddressStatus = (int?)Common.AddressStatusEnum.Active;

                            c.Entry(newAddress).State = System.Data.Entity.EntityState.Added;

                            c.SaveChanges();

                            addressOwner = c.User.FirstOrDefault(u => u.Id == newAddress.OwnerId.Value);

                            addressOwner.AddressId   = newAddress.Id;
                            addressOwner.LastUpdated = DateTime.Now;

                            c.SaveChanges();

                            return(RedirectToAction("ProfileView", "Profile"));
                        }
                    }
                    else if (ownerType > -1 && ownerId > 0)
                    {
                        addressDTO.OwnerType = ownerType;
                        addressDTO.OwnerId   = model.OwnerId;

                        using (DAL.CraveatsDbContext c = new DAL.CraveatsDbContext())
                        {
                            addressDTO.RegionId = DataSecurityTripleDES.GetEncryptedText(
                                c.Region.FirstOrDefault(r => r.CountryISO2 == "CA" &&
                                                        r.RegionAlias == addressDTO.RegionAlias).Id);

                            addressDTO.CountryId = DataSecurityTripleDES.GetEncryptedText(
                                c.Country.FirstOrDefault(s => s.ISO2 == "CA").Id);

                            DAL.Address newAddress = EntityDTOHelper.MapToEntity <AddressDTO, DAL.Address>(
                                addressDTO, null, true);
                            newAddress.AddressStatus = (int?)Common.AddressStatusEnum.Active;

                            c.Entry(newAddress).State = System.Data.Entity.EntityState.Added;

                            c.SaveChanges();

                            DAL.Restaurant restaurant = c.Restaurant.FirstOrDefault(u => u.Id == newAddress.OwnerId.Value);

                            restaurant.AddressId   = newAddress.Id;
                            restaurant.LastUpdated = DateTime.Now;

                            c.SaveChanges();

                            return(RedirectToAction("Index", "RestaurantMenu", new
                            {
                                ownerType = DataSecurityTripleDES.GetEncryptedText((int)Common.OwnerTypeEnum.ServiceProvider),
                                ownerId = DataSecurityTripleDES.GetEncryptedText(restaurant.Id)
                            }));
                        }
                    }
                    ModelState.AddModelError("", "An address exists for this owner.");
                }
            }

            // Something is not right - so render the registration page again,
            // keeping the data user has entered by supplying the model.
            return(View(model));
        }