Ejemplo n.º 1
0
        private void FillPanelUserFormModel(PanelUserFormModel model)
        {
            if (base.CurrentUser.UserId == model.UserId)
            {
                model.IsProfile = true;
            }
            if (base.CurrentUser.Role == UserRole.SuperAdmin)
            {
                model.IsSuperAdmin = true;
            }
            int?companyId = base.CurrentUser.CompanyId;

            if (base.CurrentUser.Role == UserRole.SuperAdmin)
            {
                companyId = null;
            }
            Result <List <PlaceDTO> > result = _placeService.GetAllPlaceAsync(new PlaceSearchModel
            {
                CompanyId = companyId,
                Page      = 0,
                PageSize  = 1000
            }).Result;

            if (result.IsSuccess)
            {
                model.Places = result.Data;
            }
        }
Ejemplo n.º 2
0
        public async Task <ViewResult> Update(int id)
        {
            PanelUserFormModel model = new PanelUserFormModel
            {
                UserId = id
            };

            try
            {
                Result <PanelUserDTO> result = await _panelUserService.GetUserAsync(id);

                if (result.IsSuccess)
                {
                    model = Mapper.Map <PanelUserDTO, PanelUserFormModel>(result.Data);
                }
                else
                {
                    model.FormMessage = result.FormMessage;
                }
                model.UserId = id;
                FillPanelUserFormModel(model);
                return(this.View((object)model));
            }
            catch (Exception ex)
            {
                LoggerExtensions.LogError(_logger, ex, "GET Update Error {0}", new object[1]
                {
                    id
                });
                model.FormMessage = "İşleminiz gerçekleştirilemedi.";
                return(this.View((object)model));
            }
        }
Ejemplo n.º 3
0
        public IActionResult Create()
        {
            PanelUserFormModel panelUserFormModel = new PanelUserFormModel
            {
                Role = UserRole.Dealer
            };

            FillPanelUserFormModel(panelUserFormModel);
            return(this.View((object)panelUserFormModel));
        }
Ejemplo n.º 4
0
        public async Task <ViewResult> Update(int id, PanelUserFormModel model)
        {
            model.UserId = id;
            FillPanelUserFormModel(model);
            if (this.ModelState.IsValid)
            {
                try
                {
                    PanelUserDTO panelUserDTO = Mapper.Map <PanelUserFormModel, PanelUserDTO>(model);
                    if (model.Role == UserRole.Dealer && base.CurrentUser.Role == UserRole.SuperAdmin)
                    {
                        Place place = _placeService.GetPlaceQueryable().FirstOrDefault((Place w) => (object)(int?)w.Id == (object)model.PlaceId);
                        if (place != null)
                        {
                            panelUserDTO.CompanyId = place.CompanyId;
                        }
                    }
                    Result result = await _panelUserService.UpdateUserAsync(id, panelUserDTO);

                    model.FormMessage = result.FormMessage;
                    model.IsSuccess   = result.IsSuccess;
                    if (model.IsSuccess)
                    {
                        model.FormMessage = "İşleminiz başarılı bir şekilde gerçekleştirildi.";
                    }
                    return(this.View((object)model));
                }
                catch (Exception ex)
                {
                    LoggerExtensions.LogError(_logger, ex, "POST Update Error {0}", new object[1]
                    {
                        id
                    });
                    model.FormMessage = "İşleminiz gerçekleştirilemedi.";
                    return(this.View((object)model));
                }
            }
            return(this.View((object)model));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Create(PanelUserFormModel model)
        {
            try
            {
                FillPanelUserFormModel(model);
                if (!this.ModelState.IsValid)
                {
                    return(this.View((object)model));
                }

                if (string.IsNullOrWhiteSpace(model.Email))
                {
                    model.IsSuccess   = false;
                    model.FormMessage = "E-posta adresi gerekmektedir";
                    return(this.View((object)model));
                }

                if (string.IsNullOrWhiteSpace(model.Name))
                {
                    model.IsSuccess   = false;
                    model.FormMessage = "Ad Soyad gerekmektedir";
                    return(this.View((object)model));
                }

                if (model.Role == UserRole.Dealer && !model.PlaceId.HasValue)
                {
                    model.IsSuccess   = false;
                    model.FormMessage = "Şube yetkilisi eklemek için mekan seçmeniz gerekmektedir.";
                    return(this.View((object)model));
                }

                if (model.Role == UserRole.Admin && !model.CompanyId.HasValue)
                {
                    model.IsSuccess   = false;
                    model.FormMessage = "Firma yetkilisi eklemek için mekan seçmeniz gerekmektedir.";
                    return(this.View((object)model));
                }

                var companyId = 0;

                PanelUserDTO panelUserDTO = new PanelUserDTO
                {
                    Name        = model.Name,
                    Email       = model.Email,
                    Role        = model.Role,
                    CreatedDate = DateTime.UtcNow,
                    CompanyId   = companyId = base.CurrentUser.CompanyId,
                    PlaceId     = model.PlaceId
                };
                var misafirIsletmemi = false;
                if (model.Role == UserRole.Dealer)
                {
                    Place place = _placeService.GetPlaceQueryable().FirstOrDefault((Place w) => (object)(int?)w.Id == (object)model.PlaceId);
                    if (place != null)
                    {
                        panelUserDTO.CompanyId = place.CompanyId;
                        misafirIsletmemi       = string.Equals(place.Guest, "Evet", StringComparison.InvariantCultureIgnoreCase);
                    }
                }

                if (model.Role == UserRole.Admin)
                {
                    panelUserDTO.CompanyId = model.CompanyId.Value;
                    var company = _companyService.GetCompanyQueryable().AsNoTracking().First(x => x.Id == model.CompanyId);
                    misafirIsletmemi = string.Equals(company.Demo, "Evet", StringComparison.InvariantCultureIgnoreCase);
                }
                panelUserDTO.SendMail = !misafirIsletmemi;
                Result <PanelUserDTO> result = await _panelUserService.AddUserAsync(panelUserDTO);

                model.FormMessage = result.FormMessage;
                model.IsSuccess   = result.IsSuccess;
                if (model.IsSuccess)
                {
                    model.FormMessage = "İşleminiz başarılı bir şekilde gerçekleştirildi.";
                }
                return(this.View((object)model));
            }
            catch (Exception ex)
            {
                LoggerExtensions.LogError(_logger, ex, "Create Error", Array.Empty <object>());
                model.IsSuccess   = false;
                model.FormMessage = "İşleminiz gerçekleştirilemedi.";
                return(this.View((object)model));
            }
        }