Exemplo n.º 1
0
        public ActionResponseModel Post([FromBody] PersonnelModel personnelModel)
        {
            ActionResponseModel response = new ActionResponseModel();

            response.Error = new List <string>();

            try
            {
                if (_personnelService.GetByEmail(personnelModel.Email) != null ||
                    _userService.GetByEmail(personnelModel.Email) != null)
                {
                    response.Error.Add("Email already used");
                }

                if (response.Error.Count > 0)
                {
                    response.Success = false;
                }
                else
                {
                    var businessId = _personnelService.GetByEmail(User.Identity.Name).BusinessId;
                    _personnelService.Create(businessId, personnelModel.ToDBModel());
                    response.Success = true;
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error.Add(ex.Message);
            }
            return(response);
        }
Exemplo n.º 2
0
        public ActionResponseModel Post([FromBody] UserModel userModel)
        {
            ActionResponseModel response = new ActionResponseModel();

            response.Error = new List <string>();
            try
            {
                if (_userService.GetByEmail(userModel.Email) != null ||
                    _personnelService.GetByEmail(userModel.Email) != null)
                {
                    response.Error.Add("Email address already used");
                }

                if (response.Error.Count > 0)
                {
                    response.Success = false;
                }
                else
                {
                    _userService.Create(userModel.ToDBModel());
                    response.Success = true;
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error.Add(ex.Message);
            }
            return(response);
        }
Exemplo n.º 3
0
        public ActionResponseModel PutSchedule(int id, ScheduleModel scheduleModel)
        {
            ActionResponseModel response = new ActionResponseModel();

            response.Error = new List <string>();

            try
            {
                var emailAddress = User.Identity.Name;
                var user         = _userService.GetByEmail(emailAddress);

                if (response.Error.Count() > 0)
                {
                    response.Success = false;
                    response.Result  = null;
                }
                else
                {
                    var schedule = _scheduleService.GetSchedule(id);
                    _scheduleService.Update(scheduleModel.ToUpdateDBModel(schedule));
                    response.Success = true;
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error.Add(ex.Message);
            }
            return(response);
        }
Exemplo n.º 4
0
        public ActionResponseModel GetSchedules()
        {
            ActionResponseModel response = new ActionResponseModel();

            response.Error = new List <string>();

            try
            {
                var emailAddress = User.Identity.Name;
                var user         = _personnelService.GetByEmail(emailAddress);

                if (response.Error.Count() > 0)
                {
                    response.Success = false;
                    response.Result  = null;
                }
                else
                {
                    List <ScheduleListModel> result = _scheduleService.GetScheduleBusiness(user.BusinessId)
                                                      .Select(model => new ScheduleListModel(model)).ToList();

                    response.Success = true;
                    response.Result  = result;
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error.Add(ex.Message);
            }
            return(response);
        }
Exemplo n.º 5
0
        public ActionResponseModel Get()
        {
            ActionResponseModel response = new ActionResponseModel();

            response.Error = new List <string>();
            try
            {
                var user = _userService.GetByEmail(User.Identity.Name);
                if (user == null)
                {
                    response.Result = null;
                }
                else
                {
                    response.Result = new UserModel(user);
                }

                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error.Add(ex.Message);
            }

            return(response);
        }
Exemplo n.º 6
0
        public ActionResponseModel Put(int id, [FromBody]  ServiceModel serviceListModel)
        {
            ActionResponseModel response = new ActionResponseModel();

            response.Error = new List <string>();

            try
            {
                var businessId = _personnel.GetByEmail(User.Identity.Name).BusinessId;
                var service    = _servicesService.Get(id);

                if (businessId != service.BusinessId)
                {
                    response.Error.Add("Service not found");
                }

                if (response.Error.Count() > 0)
                {
                    response.Success = false;
                    response.Result  = null;
                }
                else
                {
                    _servicesService.Update(id, businessId, serviceListModel.ToDbModel());
                    response.Success = true;
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error.Add(ex.Message);
            }
            return(response);
        }
Exemplo n.º 7
0
        public ActionResponseModel Put([FromBody] BusinessModel businessListModel)
        {
            ActionResponseModel response = new ActionResponseModel();

            response.Error = new List <string>();
            try
            {
                var user     = _personnelService.GetByEmail(User.Identity.Name);
                var business = _businessService.FindByName(businessListModel.Name);
                if (business != null && business.Id != user.BusinessId)
                {
                    response.Error.Add("Business name already used");
                }



                if (response.Error.Count > 0)
                {
                    response.Success = false;
                }
                else
                {
                    _businessService.Update(user.BusinessId, businessListModel.ToDBModel());
                    response.Success = true;
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error.Add(ex.Message);
            }

            return(response);
        }
Exemplo n.º 8
0
        public ActionResponseModel Put([FromBody] PersonnelModel personnelModel)
        {
            ActionResponseModel response = new ActionResponseModel();

            response.Error = new List <string>();

            try
            {
                if (personnelModel.Email != null &&
                    personnelModel.Email != User.Identity.Name)
                {
                    response.Error.Add("Email address is not editable");
                }

                if (response.Error.Count > 0)
                {
                    response.Success = false;
                }
                else
                {
                    var personnel = _personnelService.GetByEmail(User.Identity.Name);
                    _personnelService.Update(personnelModel.ToUpdateDBModel(personnel));
                    response.Success = true;
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error.Add(ex.Message);
            }
            return(response);
        }
Exemplo n.º 9
0
        public ActionResponseModel Get()
        {
            ActionResponseModel response = new ActionResponseModel();

            response.Error = new List <string>();

            try
            {
                PersonnelListModel personnelModel;
                var personnel = _personnelService.GetByEmail(User.Identity.Name);
                if (personnel == null)
                {
                    personnelModel = null;
                }
                else
                {
                    personnelModel = new PersonnelListModel(personnel);
                }

                response.Success = true;
                response.Result  = personnelModel;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error.Add(ex.Message);
            }
            return(response);
        }
Exemplo n.º 10
0
        public ActionResponseModel Post([FromBody] ServiceModel service)
        {
            ActionResponseModel result = new ActionResponseModel();

            result.Error = new List <string>();
            try
            {
                var businessId = _personnel.GetByEmail(User.Identity.Name).BusinessId;
                _servicesService.Create(businessId, service.ToDbModel());

                result.Success = true;
            }
            catch (Exception ex)
            {
                result.Error.Add(ex.Message);
                result.Success = false;
            }
            return(result);
        }
Exemplo n.º 11
0
        public ActionResponseModel GetAll()
        {
            ActionResponseModel response = new ActionResponseModel();

            response.Error = new List <string>();

            try
            {
                List <BusinessModel> result = _businessService.GetAll()
                                              .Select(x => new BusinessModel(x)).ToList();
                response.Success = true;
                response.Result  = result;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error.Add(ex.Message);
            }
            return(response);
        }
Exemplo n.º 12
0
        public ActionResponseModel Put([FromBody] UserModel userModel)
        {
            ActionResponseModel response = new ActionResponseModel();

            response.Error = new List <string>();

            try
            {
                var user = _userService.GetByEmail(User.Identity.Name);

                _userService.Update(user.Id, userModel.ToDBModel());
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error.Add(ex.Message);
            }

            return(response);
        }
Exemplo n.º 13
0
        public ActionResponseModel Get()
        {
            ActionResponseModel response = new ActionResponseModel();

            response.Error = new List <string>();
            try
            {
                var businessId = _personnel.GetByEmail(User.Identity.Name).BusinessId;
                List <ServiceListModel> result = _servicesService.GetServices(businessId)
                                                 .Select(x => new ServiceListModel(x)).ToList();

                response.Result  = result;
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Error.Add(ex.Message);
                response.Success = false;
            }
            return(response);
        }
Exemplo n.º 14
0
        public ActionResponseModel Post([FromBody] BusinessRegisterModel registerBusiness)
        {
            ActionResponseModel response = new ActionResponseModel();

            response.Error = new List <string>();
            try
            {
                if (_personnelService.GetByEmail(registerBusiness.PersonnelEmail) != null ||
                    _userService.GetByEmail(registerBusiness.PersonnelEmail) != null)
                {
                    response.Error.Add("Email already used");
                }

                if (_businessService.FindByName(registerBusiness.Name) != null)
                {
                    response.Error.Add("Business name already used");
                }


                if (response.Error.Count > 0)
                {
                    response.Success = false;
                }
                else
                {
                    //Register business
                    var businessId = _businessService.Create(registerBusiness.ToBusinessDBModel());
                    //business admin add
                    _personnelService.Create(businessId, registerBusiness.ToPersonnelDBModel());
                    response.Success = true;
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error.Add(ex.Message);
            }

            return(response);
        }
Exemplo n.º 15
0
        public ActionResponseModel Post([FromBody] CompanyListModel value)
        {
            ActionResponseModel response = new ActionResponseModel();

            try
            {
                // Create News
                companyService.Create(value.ToDBModel());

                // Build Response
                response.Id      = value.Id;
                response.Success = true;
                response.Error   = null;
            }
            catch (Exception ex)
            {
                response.Id      = -1;
                response.Success = false;
                response.Error   = ex.Message;
            }
            return(response);
        }
Exemplo n.º 16
0
        public ActionResponseModel PostSchedule([FromBody] ScheduleModel scheduleModel)
        {
            ActionResponseModel response = new ActionResponseModel();

            response.Error = new List <string>();

            try
            {
                var emailAddress = User.Identity.Name;
                var user         = _userService.GetByEmail(emailAddress);

                if (_servicesService.Get(scheduleModel.ServiceId) == null)
                {
                    response.Error.Add("Service not found");
                }

                if (scheduleModel.DateTime < DateTime.Now)
                {
                    response.Error.Add("Schedule date is invalid");
                }

                if (response.Error.Count() > 0)
                {
                    response.Success = false;
                    response.Result  = null;
                }
                else
                {
                    _scheduleService.Create(user.Id, scheduleModel.ToDBModel());
                    response.Success = true;
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error.Add(ex.Message);
            }
            return(response);
        }
Exemplo n.º 17
0
        public ActionResponseModel Get()
        {
            ActionResponseModel response = new ActionResponseModel();

            response.Error = new List <string>();
            try
            {
                var           user = _personnelService.GetByEmail(User.Identity.Name);
                BusinessModel businessListModel;
                var           business = _businessService.Get(user.BusinessId);
                if (business == null)
                {
                    response.Error.Add("Business not found");
                }

                if (response.Error.Count() > 0)
                {
                    response.Success = false;
                    response.Result  = null;
                }
                else
                {
                    businessListModel = new BusinessModel(business);

                    response.Success = true;
                    response.Result  = businessListModel;
                }

                return(response);
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error.Add(ex.Message);
            }

            return(response);
        }
Exemplo n.º 18
0
        public ActionResponseModel Delete(int id)
        {
            ActionResponseModel response = new ActionResponseModel();

            try
            {
                // Delete
                companyService.Delete(id);

                // Build Response
                response.Id      = id;
                response.Success = true;
                response.Error   = null;
            }
            catch (Exception ex)
            {
                response.Id      = -1;
                response.Success = false;
                response.Error   = ex.Message;
            }

            return(response);
        }
Exemplo n.º 19
0
        public ActionResponseModel Put(int id, [FromBody] CompanyListModel value)
        {
            ActionResponseModel response = new ActionResponseModel();

            try
            {
                // Update
                companyService.Update(id, value.ToDBModel());

                // Build Response
                response.Id      = id;
                response.Success = true;
                response.Error   = null;
            }
            catch (Exception ex)
            {
                response.Id      = -1;
                response.Success = false;
                response.Error   = ex.Message;
            }

            return(response);
        }
Exemplo n.º 20
0
        public ActionResponseModel GetServices(int id)
        {
            ActionResponseModel response = new ActionResponseModel();

            response.Error = new List <string>();
            try
            {
                var business = _businessService.Get(id);
                if (business == null)
                {
                    response.Error.Add("Business not found");
                }

                if (response.Error.Count() > 0)
                {
                    response.Success = false;
                    response.Result  = null;
                }
                else
                {
                    List <ServiceListModel> result = _servicesService.GetServices(id)
                                                     .Select(x => new ServiceListModel(x)).ToList();


                    response.Success = true;
                    response.Result  = result;
                }

                return(response);
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error.Add(ex.Message);
            }
            return(response);
        }
Exemplo n.º 21
0
        public ActionResponseModel Get(int id)
        {
            ActionResponseModel response = new ActionResponseModel();

            response.Error = new List <string>();
            try
            {
                BusinessModel businessListModel;
                var           business = _businessService.Get(id);
                if (business == null)
                {
                    response.Error.Add("Business not found");
                }

                if (response.Error.Count() > 0)
                {
                    response.Success = false;
                    response.Result  = null;
                }
                else
                {
                    businessListModel = new BusinessModel(business);

                    response.Success = true;
                    response.Result  = businessListModel;
                }

                return(response);
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error.Add(ex.Message);
            }
            return(response);
        }
Exemplo n.º 22
0
        public ActionResponseModel GetSchedule(int id)
        {
            ActionResponseModel response = new ActionResponseModel();

            response.Error = new List <string>();

            try
            {
                var emailAddress = User.Identity.Name;
                var user         = _userService.GetByEmail(emailAddress);

                if (_scheduleService.GetSchedule(id).UserId == user.Id)
                {
                    response.Error.Add("Unable to access this schedule");
                }

                if (response.Error.Count() > 0)
                {
                    response.Success = false;
                    response.Result  = null;
                }
                else
                {
                    var           schedule = _scheduleService.GetSchedule(id);
                    ScheduleModel result   = new ScheduleModel(schedule);
                    response.Success = true;
                    response.Result  = result;
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error.Add(ex.Message);
            }
            return(response);
        }