public async Task <bool> Update(BusinessDTM item)
        {
            try
            {
                Business business = new Business();
                business.Id                 = item.Id;
                business.Name               = item.Name;
                business.Phone              = item.Phone;
                business.Logo               = item.Logo;
                business.Webpage            = item.Webpage;
                business.Address            = item.Address;
                business.City               = item.City;
                business.State              = item.State;
                business.ZipCode            = item.ZipCode;
                business.RegistrationNumber = item.RegistrationNumber;
                business.Country            = await Database.BllServices.GetCountry(item.Country.Id);

                business.Currency = await Database.BllServices.GetCurrency(item.Currency.Id);

                business.Time_zone = await Database.BllServices.GetTime_zone(item.Time_zone.Id);

                //business.Booking.BusinessId = item.Booking.BusinessId;
                //business.Services = item.Services;
                //business.Clients = item.Clients;
                //business.Employees = item.Employees;
                await Database.Businesses.Update(business);

                return(true);
            }
            catch (Exception ex) { Console.Out.WriteLine(ex.Message); return(false); }
        }
Beispiel #2
0
        public static BookingDTM changeToDTM(Booking booking)
        {
            BookingDTM bDtm = new BookingDTM();

            bDtm.BusinessId             = booking.BusinessId;
            bDtm.WebpageLink            = booking.WebpageLink;
            bDtm.IsEntityLogoRemoved    = booking.IsEntityLogoRemoved;
            bDtm.IsMemberSelecting      = booking.IsMemberSelecting;
            bDtm.SlotDuration           = booking.SlotDuration;
            bDtm.PageLanguageId         = booking.PageLanguageId;
            bDtm.BannerPicture          = booking.BannerPicture;
            bDtm.SklypeLink             = booking.SklypeLink;
            bDtm.FacebookLink           = booking.FacebookLink;
            bDtm.TwitterLink            = booking.TwitterLink;
            bDtm.InstagramkLink         = booking.InstagramkLink;
            bDtm.YoutubeLink            = booking.YoutubeLink;
            bDtm.PageOverview           = booking.PageOverview;
            bDtm.IsContactsAvailable    = booking.IsContactsAvailable;
            bDtm.IsServicesAvailable    = booking.IsServicesAvailable;
            bDtm.IsPriceAvailable       = booking.IsPriceAvailable;
            bDtm.IsDurationAvailable    = booking.IsDurationAvailable;
            bDtm.IsDescriptionAvailable = booking.IsDescriptionAvailable;

            if (booking.Business != null)
            {
                BusinessDTM businessDtm = new BusinessDTM();
                businessDtm.Id                 = booking.Business.Id;
                businessDtm.Name               = booking.Business.Name;
                businessDtm.Phone              = booking.Business.Phone;
                businessDtm.Logo               = booking.Business.Logo;
                businessDtm.Webpage            = booking.Business.Webpage;
                businessDtm.Address            = booking.Business.Address;
                businessDtm.City               = booking.Business.City;
                businessDtm.State              = booking.Business.State;
                businessDtm.ZipCode            = booking.Business.ZipCode;
                businessDtm.RegistrationNumber = booking.Business.RegistrationNumber;
                if (booking.Business.Country != null)
                {
                    businessDtm.Country = changeToDTM(booking.Business.Country);
                }
                if (booking.Business.Currency != null)
                {
                    businessDtm.Currency = changeToDTM(booking.Business.Currency);
                }
                if (booking.Business.Country != null)
                {
                    businessDtm.Time_zone = changeToDTM(booking.Business.Time_zone);
                }
                //if (booking.Business.Booking != null)
                //    businessDtm.Booking = changeToDTM(booking.Business.Booking);

                bDtm.Business = businessDtm;
            }

            return(bDtm);
        }
Beispiel #3
0
        // POST: Businesses/businessDTM
        public async Task <HttpResponseMessage> Post([FromBody] BusinessDTM businessDtm)
        {
            try
            {
                int id = await TheRepo.BusinessesDTM.Create(businessDtm);

                return(Request.CreateResponse(HttpStatusCode.Created, id));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Beispiel #4
0
        public static BusinessDTM changeToDTM(Business business)
        {
            BusinessDTM bDtm = new BusinessDTM();

            bDtm.Id                 = business.Id;
            bDtm.Name               = business.Name;
            bDtm.Phone              = business.Phone;
            bDtm.Logo               = business.Logo;
            bDtm.Webpage            = business.Webpage;
            bDtm.Address            = business.Address;
            bDtm.City               = business.City;
            bDtm.State              = business.State;
            bDtm.ZipCode            = business.ZipCode;
            bDtm.RegistrationNumber = business.RegistrationNumber;

            if (business.Country != null)
            {
                CountryDTM country = new CountryDTM();
                country.Id          = business.Country.Id;
                country.Code        = business.Country.Code;
                country.Name        = business.Country.Name;
                country.Native      = business.Country.Native;
                country.PhonePrefix = business.Country.PhonePrefix;
                country.Capital     = business.Country.Capital;
                country.Currency_   = business.Country.Currency_;
                country.Emoji       = business.Country.Emoji;
                country.EmojiU      = business.Country.EmojiU;
                bDtm.Country        = country;
                bDtm.CountryId      = business.Country.Id;
            }
            if (business.Currency != null)
            {
                CurrencyDTM currency = new CurrencyDTM();
                currency.Id     = business.Currency.Id;
                currency.Name   = business.Currency.Name;
                bDtm.Currency   = currency;
                bDtm.CurrencyId = business.Currency.Id;
            }
            if (business.Time_zone != null)
            {
                Time_zoneDTM tz = new Time_zoneDTM();
                tz.Id             = business.Time_zone.Id;
                tz.Zone           = business.Time_zone.Zone;
                tz.CountryCode    = business.Time_zone.CountryCode;
                tz.UTC_Jan_1_2020 = business.Time_zone.UTC_Jan_1_2020;
                tz.DST_Jul_1_2020 = business.Time_zone.DST_Jul_1_2020;
                bDtm.Time_zone    = tz;
                bDtm.Time_zoneId  = business.Time_zone.Id;
            }
            return(bDtm);
        }
Beispiel #5
0
        public static Business changeFromDTM(BusinessDTM businessDtm)
        {
            Business business = new Business();

            business.Id                 = businessDtm.Id;
            business.Name               = businessDtm.Name;
            business.Phone              = businessDtm.Phone;
            business.Logo               = businessDtm.Logo;
            business.Webpage            = businessDtm.Webpage;
            business.Address            = businessDtm.Address;
            business.City               = businessDtm.City;
            business.State              = businessDtm.State;
            business.ZipCode            = businessDtm.ZipCode;
            business.RegistrationNumber = businessDtm.RegistrationNumber;
            business.Country            = businessDtm.Country == null ? null : changeFromDTM(businessDtm.Country);
            business.Currency           = businessDtm.Currency == null ? null : changeFromDTM(businessDtm.Currency);
            business.Time_zone          = businessDtm.Time_zone == null ? null : changeFromDTM(businessDtm.Time_zone);
            business.Booking            = businessDtm.Booking == null ? null : changeFromDTM(businessDtm.Booking);
            return(business);
        }
Beispiel #6
0
        public async Task <HttpResponseMessage> Put([FromBody] BusinessDTM businessDtm)
        {
            try
            {
                var originalBusiness = TheRepo.BusinessesDTM.Get(businessDtm.Id);

                if (originalBusiness == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotModified, "Item is not found"));
                }
                else
                {
                    await TheRepo.BusinessesDTM.Update(businessDtm);

                    return(Request.CreateResponse(HttpStatusCode.OK, businessDtm));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
        public async Task <List <BusinessDTM> > GetAll(SearchParams search)
        {
            //var config = new MapperConfiguration(cfg => {
            //    cfg.CreateMap<Business, BusinessDTM>();
            //    cfg.CreateMap<Country, CountryDTM>();
            //    cfg.CreateMap<Currency, CurrencyDTM>();
            //    cfg.CreateMap<Time_zone, Time_zoneDTM>();
            //    cfg.CreateMap<Booking, BookingDTM>();
            //});
            //var mapper = new Mapper(config);
            //return await Task.Run(() => (mapper.Map<List<BusinessDTM>>(
            //    Database.Businesses.GetAll()
            //   .OrderBy(u => u.Name)
            //   .Skip(search.PageSize * search.Page)
            //   .Take(search.PageSize))));
            //return mapper.Map<List<BusinessDTM>>(
            //       Database.Businesses.GetAll()
            //      .OrderBy(u => u.Name)
            //      .Skip(search.PageSize * search.Page)
            //      .Take(search.PageSize));
            List <BusinessDTM> bListDtm = new List <BusinessDTM>();
            List <Business>    bList    = Database.Businesses.GetAll()
                                          .OrderBy(u => u.Name)
                                          .Skip(search.PageSize * search.Page)
                                          .Take(search.PageSize).ToList();

            foreach (Business b in bList)
            {
                BusinessDTM bDtm = new BusinessDTM();
                bDtm.Id                 = b.Id;
                bDtm.Name               = b.Name;
                bDtm.Phone              = b.Phone;
                bDtm.Logo               = b.Logo;
                bDtm.Webpage            = b.Webpage;
                bDtm.Address            = b.Address;
                bDtm.City               = b.City;
                bDtm.State              = b.State;
                bDtm.ZipCode            = b.ZipCode;
                bDtm.RegistrationNumber = b.RegistrationNumber;

                bDtm.CountryId   = b.Country.Id;
                bDtm.CurrencyId  = b.Currency.Id;
                bDtm.Time_zoneId = b.Time_zone.Id;

                CountryDTM country = new CountryDTM();
                country.Id          = b.Country.Id;
                country.Code        = b.Country.Code;
                country.Name        = b.Country.Name;
                country.Native      = b.Country.Native;
                country.PhonePrefix = b.Country.PhonePrefix;
                country.Capital     = b.Country.Capital;
                country.Currency_   = b.Country.Currency_;
                country.Emoji       = b.Country.Emoji;
                country.EmojiU      = b.Country.EmojiU;
                bDtm.Country        = country;

                CurrencyDTM currency = new CurrencyDTM();
                currency.Id   = b.Currency.Id;
                currency.Name = b.Currency.Name;
                bDtm.Currency = currency;

                Time_zoneDTM tz = new Time_zoneDTM();
                tz.Id             = b.Time_zone.Id;
                tz.Zone           = b.Time_zone.Zone;
                tz.CountryCode    = b.Time_zone.CountryCode;
                tz.UTC_Jan_1_2020 = b.Time_zone.UTC_Jan_1_2020;
                tz.DST_Jul_1_2020 = b.Time_zone.DST_Jul_1_2020;
                bDtm.Time_zone    = tz;

                bListDtm.Add(bDtm);
            }

            return(bListDtm);
        }
        public async Task <int> Create(BusinessDTM businessDtm)
        {
            try
            {
                Business business = new Business();
                business.Name = businessDtm.Name;
                if (businessDtm.Country != null)
                {
                    business.Phone              = businessDtm.Phone;
                    business.Logo               = businessDtm.Logo;
                    business.Webpage            = businessDtm.Webpage;
                    business.Address            = businessDtm.Address;
                    business.City               = businessDtm.City;
                    business.State              = businessDtm.State;
                    business.ZipCode            = businessDtm.ZipCode;
                    business.RegistrationNumber = businessDtm.RegistrationNumber;
                    business.Country            = await Database.Countries.Get(businessDtm.Country.Id);

                    business.Currency = await Database.Currencies.Get(businessDtm.Currency.Id);

                    business.Time_zone = await Database.Time_zones.Get(businessDtm.Time_zone.Id);

                    business.Booking = businessDtm.Booking == null ? null : await Database.Bookings.Get(businessDtm.Booking.BusinessId);

                    business.Services  = null;
                    business.Clients   = null;
                    business.Employees = null;
                }
                await Database.Businesses.Create(business);

                User user = await Database.BllServices.GetUser(businessDtm.UserId);

                Booking booking = new Booking();
                booking.BusinessId = business.Id;
                await Database.Bookings.Create(booking);

                Employee employeeBoss = new Employee();
                employeeBoss.IsOwner  = true;
                employeeBoss.Business = business;
                employeeBoss.User     = user;
                await Database.Employees.Create(employeeBoss);

                WorkingHour wHourDtm = new WorkingHour();
                wHourDtm.Employee   = employeeBoss;
                wHourDtm.EmployeeId = employeeBoss.Id;
                await Database.WorkingHours.Create(wHourDtm);

                Permission perm = new Permission();
                perm.Employee   = employeeBoss;
                perm.EmployeeId = employeeBoss.Id;
                await Database.Permissions.Create(perm);

                CalendarSetting cSetting = new CalendarSetting();
                cSetting.Employee   = employeeBoss;
                cSetting.EmployeeId = employeeBoss.Id;
                await Database.CalendarSettings.Create(cSetting);

                CustomerNotification cNotif = new CustomerNotification();
                cNotif.Employee   = employeeBoss;
                cNotif.EmployeeId = employeeBoss.Id;
                await Database.CustomerNotifications.Create(cNotif);

                TeamNotification tNotif = new TeamNotification();
                tNotif.Employee   = employeeBoss;
                tNotif.EmployeeId = employeeBoss.Id;
                await Database.TeamNotifications.Create(tNotif);

                return(business.Id);
            }
            catch { return(0); }
        }
        public async Task <BusinessDTM> Get(int id)
        {
            int firstBusinessId = 1;

            if (id < firstBusinessId)
            {
                throw new ValidationException("Business id is not specified correctly", "");
            }
            var business = await Database.Businesses.Get(id);

            if (business == null)
            {
                throw new ValidationException("Business is not found", "");
            }

            BusinessDTM bDtm = new BusinessDTM();

            bDtm.Id                 = business.Id;
            bDtm.Name               = business.Name;
            bDtm.Phone              = business.Phone;
            bDtm.Logo               = business.Logo;
            bDtm.Webpage            = business.Webpage;
            bDtm.Address            = business.Address;
            bDtm.City               = business.City;
            bDtm.State              = business.State;
            bDtm.ZipCode            = business.ZipCode;
            bDtm.RegistrationNumber = business.RegistrationNumber;

            if (business.Country != null)
            {
                CountryDTM country = new CountryDTM();
                country.Id          = business.Country.Id;
                country.Code        = business.Country.Code;
                country.Name        = business.Country.Name;
                country.Native      = business.Country.Native;
                country.PhonePrefix = business.Country.PhonePrefix;
                country.Capital     = business.Country.Capital;
                country.Currency_   = business.Country.Currency_;
                country.Emoji       = business.Country.Emoji;
                country.EmojiU      = business.Country.EmojiU;
                bDtm.Country        = country;
                bDtm.CountryId      = business.Country.Id;
            }
            if (business.Currency != null)
            {
                CurrencyDTM currency = new CurrencyDTM();
                currency.Id     = business.Currency.Id;
                currency.Name   = business.Currency.Name;
                bDtm.Currency   = currency;
                bDtm.CurrencyId = business.Currency.Id;
            }
            if (business.Time_zone != null)
            {
                Time_zoneDTM tz = new Time_zoneDTM();
                tz.Id             = business.Time_zone.Id;
                tz.Zone           = business.Time_zone.Zone;
                tz.CountryCode    = business.Time_zone.CountryCode;
                tz.UTC_Jan_1_2020 = business.Time_zone.UTC_Jan_1_2020;
                tz.DST_Jul_1_2020 = business.Time_zone.DST_Jul_1_2020;
                bDtm.Time_zone    = tz;
                bDtm.Time_zoneId  = business.Time_zone.Id;
            }
            //var config = new MapperConfiguration(cfg => cfg.CreateMap<Business, BusinessDTM>());
            //var mapper = new Mapper(config);
            //return mapper.Map<BusinessDTM>(business);
            return(bDtm);
        }
Beispiel #10
0
        public async Task <IHttpActionResult> Register(RegisterBindingModel model)
        {
            IdentityResult result = null;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser()
                {
                    UserName = model.Email, Email = model.Email, FirstName = model.FirstName
                };
                result = await UserManager.CreateAsync(user, model.Password);


                if (result.Succeeded)
                {
                    // генерируем токен для подтверждения регистрации
                    var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                    // создаем ссылку для подтверждения
                    var callbackUrl = Url.Link("Default", new
                    {
                        Controller = "Account",
                        Action     = "ConfirmEmail",
                        userId     = user.Id,
                        code       = code
                    });
                    // отправка письма
                    await UserManager.SendEmailAsync(user.Id, "Подтверждение электронной почты",
                                                     "Для завершения регистрации перейдите по ссылке:: <a href=\""
                                                     + callbackUrl + "\">завершить регистрацию</a>");

                    UserDTM newUser = new UserDTM();
                    newUser.Id    = user.Id; newUser.FirstName = user.FirstName;
                    newUser.Email = user.UserName;
                    if (model.MemberPlan == 1)
                    {
                        await UserManager.AddToRoleAsync(user.Id, "FreeMember");

                        newUser.PlanId = 1;
                    }
                    if (model.MemberPlan == 2)
                    {
                        await UserManager.AddToRoleAsync(user.Id, "GoldMember");

                        newUser.PlanId = 2;
                    }
                    if (model.MemberPlan == 3)
                    {
                        await UserManager.AddToRoleAsync(user.Id, "PlatinumMember");

                        newUser.PlanId = 3;
                    }
                    if (model.MemberPlan == 777)
                    {
                        await UserManager.AddToRoleAsync(user.Id, "Admin");

                        newUser.PlanId = 777;
                    }
                    if (model.MemberPlan == 888)
                    {
                        await UserManager.AddToRoleAsync(user.Id, "Moderator");

                        newUser.PlanId = 888;
                    }
                    else
                    {
                        Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Try again!");
                    }

                    await TheRepo.UsersDTM.Create(newUser);

                    BusinessDTM busines = new BusinessDTM();
                    busines.Name = model.BusinessName;
                    int businessId = await TheRepo.BusinessesDTM.Create(busines);
                }
            }
            //-----------------------------
            //DpapiDataProtectionProvider provider = new DpapiDataProtectionProvider("WebApi");
            //var userStore = new UserStore<ApplicationUser>(new ApplicationDbContext());
            //var userManager = new UserManager<ApplicationUser>(userStore)
            //{
            //    PasswordValidator = new PasswordValidator
            //    {
            //        RequiredLength = 3
            //    },
            //    UserTokenProvider = new DataProtectorTokenProvider<ApplicationUser>(provider.Create("EmailConfirmation"))
            //};
            //var user = new ApplicationUser()
            //{
            //    UserName = model.Email,
            //    Email = model.Email,
            //    FirstName = model.FirstName
            //};
            //result = userManager.Create(user, model.Password);
            //if (user != null)
            //{
            //    string code = userManager.GenerateEmailConfirmationToken(user.Id);
            //    code = HttpUtility.UrlEncode(code);
            //    try
            //    {
            //        var emailService = new EmailService();
            //        string callbackUrl = Url.Link("DefaultApi", new { controller = "Account/ConfirmEmail", userId = user.Id, code });
            //        string body = "<h5>Welcome " + model.Email + "! Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</h5>";
            //        //emailService. .GenerateEmailConfirmationBody(body, callbackUrl);
            //        string from = ConfigurationManager.AppSettings["From"];
            //        string to = user.Email;
            //        string subject = ConfigurationManager.AppSettings["EmailConfirmation"];
            //        IdentityMessage message = new IdentityMessage { Destination = to, Subject = "Account Confirmation", Body = body };
            //        await emailService.SendAsync(message);
            //            //emailService.GenerateEmailHistoryEntry(message, user.Email, client, "Email Confirmation");

            //    }
            //    catch (Exception)
            //    {
            //        throw;
            //    }


            //}


            //-----------------------------
            return(Ok());
        }