コード例 #1
0
 public int SetupBusinessHours(long serviceLocationId)
 {
     try
     {
         var today = DateTime.Now;
         var date  = new DateTime(today.Year, today.Month, today.Day, 8, 00, 00, DateTimeKind.Utc);
         for (int i = 0; i < 7; i++)
         {
             var businessHour = new tblBusinessHour()
             {
                 WeekDayId         = i,
                 IsStartDay        = i == 0 ? true : false,
                 IsHoliday         = false,
                 From              = date,
                 To                = date.AddHours(10),
                 IsSplit1          = false,
                 FromSplit1        = null,
                 ToSplit1          = null,
                 IsSplit2          = false,
                 FromSplit2        = null,
                 ToSplit2          = null,
                 ServiceLocationId = serviceLocationId
             };
             _db.tblBusinessHours.Add(businessHour);
         }
         return(_db.SaveChanges());
     }
     catch
     {
         return(0);
     }
 }
コード例 #2
0
        public bool BusinessHourDefaultSetup(long serviceLocationId)
        {
            var result = false;

            try
            {
                var now = DateTime.Now;
                for (var i = 0; i < 7; i++)
                {
                    var businessHour = new tblBusinessHour()
                    {
                        WeekDayId         = i,
                        IsStartDay        = i == 1 ? true : false,
                        IsHoliday         = i == 1 ? true : false,
                        From              = new DateTime(now.Year, now.Month, now.Day, 8, 0, 0, DateTimeKind.Utc),
                        To                = new DateTime(now.Year, now.Month, now.Day, 18, 0, 0, DateTimeKind.Utc),
                        IsSplit1          = false,
                        FromSplit1        = new DateTime(now.Year, now.Month, now.Day, 8, 0, 0, DateTimeKind.Utc),
                        ToSplit1          = new DateTime(now.Year, now.Month, now.Day, 18, 0, 0, DateTimeKind.Utc),
                        IsSplit2          = false,
                        FromSplit2        = new DateTime(now.Year, now.Month, now.Day, 8, 0, 0, DateTimeKind.Utc),
                        ToSplit2          = new DateTime(now.Year, now.Month, now.Day, 18, 0, 0, DateTimeKind.Utc),
                        ServiceLocationId = serviceLocationId
                    };
                    _db.tblBusinessHours.Add(businessHour);
                }
                var response = _db.SaveChanges();
                if (response > 0)
                {
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            catch
            {
                result = false;
            }
            return(result);
        }
コード例 #3
0
 // POST: api/businesshour
 public IHttpActionResult Post([FromBody] BusinessHourViewModel model)
 {
     try
     {
         if (model != null && model.From > DateTime.Now)
         {
             var businessHour = new tblBusinessHour()
             {
                 WeekDayId         = model.WeekDayId,
                 IsStartDay        = model.IsStartDay,
                 IsHoliday         = model.IsHoliday,
                 From              = model.From,
                 To                = model.To,
                 IsSplit1          = model.IsSplit1,
                 FromSplit1        = model.FromSplit1,
                 ToSplit1          = model.ToSplit1,
                 IsSplit2          = model.IsSplit2,
                 FromSplit2        = model.FromSplit2,
                 ToSplit2          = model.ToSplit2,
                 ServiceLocationId = model.ServiceLocationId
             };
             _db.tblBusinessHours.Add(businessHour);
             var response = _db.SaveChanges();
             if (response > 0)
             {
                 return(Ok(new { status = true, data = businessHour, message = "success" }));
             }
             else
             {
                 return(Ok(new { status = false, data = "", message = "There was a problem." }));
             }
         }
         else
         {
             return(Ok(new { status = false, data = "", message = "Please enter a valid information." }));
         }
     }
     catch (Exception ex)
     {
         return(Ok(new { status = false, data = "", message = ex.Message.ToString() }));
     }
 }
コード例 #4
0
        // POST: api/servicelocation
        public IHttpActionResult Post([FromBody] ServiceLocationViewModel model)
        {
            try
            {
                var serviceLocation = new tblServiceLocation()
                {
                    Name        = model.Name,
                    Description = model.Description,
                    Add1        = model.Add1,
                    Add2        = model.Add2,
                    City        = model.City,
                    State       = model.State,
                    Zip         = model.Zip,
                    CountryId   = model.CountryId,
                    Created     = DateTime.Now.ToUniversalTime(),
                    IsActive    = model.IsActive,
                    BusinessId  = model.BusinessId,
                    TimezoneId  = model.TimezoneId
                };

                using (var dbTrans = _db.Database.BeginTransaction())
                {
                    _db.tblServiceLocations.Add(serviceLocation);
                    var responseLocation = _db.SaveChanges();

                    var today = DateTime.Now;
                    var date  = new DateTime(today.Year, today.Month, today.Day, 8, 00, 00, DateTimeKind.Utc);
                    for (int i = 0; i < 7; i++)
                    {
                        var businessHour = new tblBusinessHour()
                        {
                            WeekDayId         = i,
                            IsStartDay        = i == 0 ? true : false,
                            IsHoliday         = false,
                            From              = date,
                            To                = date.AddHours(10),
                            IsSplit1          = false,
                            FromSplit1        = null,
                            ToSplit1          = null,
                            IsSplit2          = false,
                            FromSplit2        = null,
                            ToSplit2          = null,
                            ServiceLocationId = serviceLocation.Id
                        };
                        _db.tblBusinessHours.Add(businessHour);
                    }
                    var responseHour = _db.SaveChanges();
                    if (responseHour > 0 && responseLocation > 0)
                    {
                        dbTrans.Commit();
                        return(Ok(new { status = true, data = serviceLocation, message = "success" }));
                    }
                    else
                    {
                        dbTrans.Rollback();
                        return(Ok(new { status = false, data = "", message = "There was a problem." }));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Ok(new { status = false, data = "", message = ex.Message.ToString() }));
            }
        }
コード例 #5
0
        public ResponseViewModel <RegisterViewModel> Register(RegisterViewModel model)
        {
            var data = new ResponseViewModel <RegisterViewModel>();

            var hasName  = _db.tblBusinesses.Any(d => d.Name.ToLower() == model.Business.Name.ToLower());
            var hasEmail = _db.tblBusinessEmployees.Any(d => d.Email.ToLower() == model.Business.Email.ToLower());

            if (hasName)
            {
                data.Status  = false;
                data.Message = "This business name has been taken. Please try another name.";
            }
            else if (hasEmail)
            {
                data.Status  = false;
                data.Message = "This business email has been taken. Please try another email id.";
            }
            else
            {
                using (var dbTran = _db.Database.BeginTransaction())
                {
                    try
                    {
                        var business = new tblBusiness()
                        {
                            Name               = model.Business.Name,
                            ShortName          = model.Business.ShortName,
                            IsInternational    = model.Business.IsInternational,
                            FaxNumbers         = model.Business.FaxNumbers,
                            PhoneNumbers       = model.Business.PhoneNumbers,
                            Logo               = model.Business.Logo,
                            Add1               = model.Business.Add1,
                            Add2               = model.Business.Add2,
                            City               = model.Business.City,
                            State              = model.Business.State,
                            CountryId          = model.Business.CountryId,
                            Email              = model.Business.Email,
                            Website            = model.Business.Website,
                            Created            = DateTime.Now.ToUniversalTime(),
                            IsActive           = model.Business.IsActive,
                            Zip                = model.Business.Zip,
                            MembershipId       = model.Business.MembershipId,
                            BusinessCategoryId = model.Business.BusinessCategoryId,
                            TimezoneId         = model.Business.TimezoneId
                        };

                        _db.tblBusinesses.Add(business);
                        var responseBusiness = _db.SaveChanges();

                        var serviceLocation = new tblServiceLocation()
                        {
                            Name        = "Main Address",
                            Add1        = model.Business.Add1,
                            Add2        = model.Business.Add2,
                            City        = model.Business.City,
                            State       = model.Business.State,
                            CountryId   = model.Business.CountryId.Value,
                            Created     = DateTime.Now.ToUniversalTime(),
                            IsActive    = model.Business.IsActive,
                            Zip         = model.Business.Zip,
                            BusinessId  = business.Id,
                            TimezoneId  = business.TimezoneId,
                            Description = ""
                        };

                        _db.tblServiceLocations.Add(serviceLocation);
                        var responseServiceLocation = _db.SaveChanges();

                        //Setup default business hours
                        //var businessHourController = new BusinessHourController();
                        //var responseBusinessHour = businessHourController.SetupBusinessHours(serviceLocation.Id);
                        var today = DateTime.Now;
                        var date  = new DateTime(today.Year, today.Month, today.Day, 8, 00, 00, DateTimeKind.Utc);
                        for (int i = 0; i < 7; i++)
                        {
                            var businessHour = new tblBusinessHour()
                            {
                                WeekDayId         = i,
                                IsStartDay        = i == 0 ? true : false,
                                IsHoliday         = false,
                                From              = date,
                                To                = date.AddHours(10),
                                IsSplit1          = false,
                                FromSplit1        = null,
                                ToSplit1          = null,
                                IsSplit2          = false,
                                FromSplit2        = null,
                                ToSplit2          = null,
                                ServiceLocationId = serviceLocation.Id
                            };
                            _db.tblBusinessHours.Add(businessHour);
                        }
                        var responseBusinessHour = _db.SaveChanges();
                        //End

                        var businessEmployee = new tblBusinessEmployee()
                        {
                            FirstName         = model.Employee.FirstName,
                            LastName          = model.Employee.LastName,
                            Password          = Security.Encrypt(model.Employee.Password, true),
                            Email             = model.Employee.Email,
                            STD               = model.Employee.STD,
                            PhoneNumber       = model.Employee.PhoneNumber,
                            ServiceLocationId = serviceLocation.Id,
                            IsAdmin           = true,
                            Created           = DateTime.Now.ToUniversalTime(),
                            IsActive          = true
                        };
                        _db.tblBusinessEmployees.Add(businessEmployee);
                        var responseBusinessEmployee = _db.SaveChanges();

                        var businessViewModel = new BusinessViewModel()
                        {
                            Add1 = business.Add1,
                            Add2 = business.Add2,
                            BusinessCategoryId = business.BusinessCategoryId,
                            City            = business.City,
                            CountryId       = business.CountryId,
                            Created         = business.Created,
                            Email           = business.Email,
                            FaxNumbers      = business.FaxNumbers,
                            Id              = business.Id,
                            IsActive        = business.IsActive,
                            IsInternational = business.IsInternational,
                            Logo            = business.Logo,
                            MembershipId    = business.MembershipId,
                            Name            = business.Name,
                            PhoneNumbers    = business.PhoneNumbers,
                            ShortName       = business.ShortName,
                            State           = business.State,
                            TimezoneId      = business.TimezoneId,
                            Website         = business.Website,
                            Zip             = business.Zip
                        };

                        var businessEmployeeViewModel = new BusinessEmployeeViewModel()
                        {
                            Created           = businessEmployee.Created,
                            Email             = businessEmployee.Email,
                            FirstName         = businessEmployee.FirstName,
                            Id                = businessEmployee.Id,
                            IsActive          = businessEmployee.IsActive,
                            IsAdmin           = businessEmployee.IsAdmin,
                            LastName          = businessEmployee.LastName,
                            PhoneNumber       = businessEmployee.PhoneNumber,
                            ServiceLocationId = businessEmployee.ServiceLocationId,
                            STD               = businessEmployee.STD
                        };

                        if (responseBusiness > 0 && responseServiceLocation > 0 && responseBusinessEmployee > 0 && responseBusinessHour > 0)
                        {
                            data.Status        = true;
                            data.Message       = "Transaction successed.";
                            data.Data          = new RegisterViewModel();
                            data.Data.Business = new BusinessViewModel();
                            data.Data.Employee = new BusinessEmployeeViewModel();
                            data.Data.Business = businessViewModel;
                            data.Data.Employee = businessEmployeeViewModel;
                            dbTran.Commit();
                        }
                        else
                        {
                            data.Status = false;
                            var reason = "";
                            if (responseBusiness <= 0)
                            {
                                reason += "Business setup issue. ";
                            }
                            if (responseServiceLocation <= 0)
                            {
                                reason += " Service location issue.";
                            }
                            if (responseBusinessEmployee <= 0)
                            {
                                reason += " Business employee issue.";
                            }
                            if (responseBusinessHour <= 0)
                            {
                                reason += " Business hour issue.";
                            }

                            data.Message       = "Registration failed. reason: " + reason;
                            data.Data.Business = new BusinessViewModel();
                            data.Data.Employee = new BusinessEmployeeViewModel();
                            dbTran.Rollback();
                        }
                    }
                    catch (Exception ex)
                    {
                        data.Status        = false;
                        data.Message       = "Registration failed. ex: " + ex.Message.ToString();
                        data.Data.Business = new BusinessViewModel();
                        data.Data.Employee = new BusinessEmployeeViewModel();
                        dbTran.Rollback();
                    }
                }
            }
            return(data);
        }