示例#1
0
        public async Task <Result <CompanyDetailDTO> > AddCompanyAsync(CompanyDetailDTO company, PanelUserDTO manager)
        {
            Result <CompanyDetailDTO> res = new Result <CompanyDetailDTO>();

            _unitOfWork.BeginTransaction(IsolationLevel.ReadCommitted);
            try
            {
                Company entity  = Mapper.Map <CompanyDetailDTO, Company>(company);
                Company created = await _unitOfWork.EntityRepository <Company>().CreateAsync(entity);

                await _unitOfWork.SaveChangesAsync();

                manager.CompanyId = created.Id;
                manager.Role      = UserRole.Admin;
                if (!string.Equals(company.Demo, "Evet", StringComparison.InvariantCultureIgnoreCase))
                {
                    Result <PanelUserDTO> result = await _panelUserService.AddUserAsync(manager);

                    if (!result.IsSuccess)
                    {
                        _unitOfWork.Rollback();
                        return(res.Fail(result.Messages));
                    }
                }
                _unitOfWork.Commit();
                return(Result.Data(Mapper.Map <Company, CompanyDetailDTO>(created)));
            }
            catch (Exception)
            {
                _unitOfWork.Rollback();
                throw;
            }
        }
示例#2
0
        public async Task <Result> UpdateCompanyAsync(int id, CompanyDetailDTO company)
        {
            Company company2 = await _unitOfWork.EntityRepository <Company>().GetFirstAsync((Company w) => w.IsDeleted == false && w.Id == id, null);

            if (company2 == null)
            {
                return(Result.Fail("Firma bulunamadı!"));
            }
            company2.Name          = company.Name;
            company2.Address       = company.Address;
            company2.CompanyTypeId = company.CompanyTypeId;
            var demoMessage = "";

            if (!string.IsNullOrWhiteSpace(company.Demo))
            {
                if ((!string.Equals("Hayir", company2.Demo, StringComparison.InvariantCultureIgnoreCase)) &&
                    string.Equals("Hayir", company.Demo, StringComparison.InvariantCultureIgnoreCase))
                {
                    demoMessage = "Demo";
                }
            }

            company2.Demo = company.Demo;


            if (!string.IsNullOrWhiteSpace(company.Image))
            {
                company2.Image = company.Image;
            }
            await _unitOfWork.SaveChangesAsync();

            return(Result.Success(message: demoMessage));
        }
示例#3
0
        public async Task <IActionResult> Create(CompanyFormModel model)
        {
            if (this.ModelState.IsValid)
            {
                try
                {
                    if (string.IsNullOrWhiteSpace(model.ManagerName) || string.IsNullOrWhiteSpace(model.ManagerEmail))
                    {
                        model.IsSuccess   = false;
                        model.FormMessage = "Firma yetkilisi bilgileri girilmelidir.";
                        return(this.View((object)model));
                    }
                    IFormFile logoFile       = model.LogoFile;
                    string    uniqueFileName = null;
                    if (logoFile != null && logoFile.Length > 0)
                    {
                        uniqueFileName = FileHelper.GetUniqueFileName(logoFile.FileName);
                        if (string.IsNullOrWhiteSpace(_hostingEnvironment.WebRootPath))
                        {
                            _hostingEnvironment.WebRootPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot");
                        }
                        string path  = Path.Combine(_hostingEnvironment.WebRootPath, "admin/uploads");
                        string path2 = Path.Combine(path, uniqueFileName);
                        using (FileStream stream = new FileStream(path2, FileMode.Create))
                        {
                            await logoFile.CopyToAsync((Stream)stream, default(CancellationToken));
                        }
                    }
                    CompanyDetailDTO companyDetailDTO = Mapper.Map <CompanyFormModel, CompanyDetailDTO>(model);
                    companyDetailDTO.Image = uniqueFileName;
                    PanelUserDTO manager = new PanelUserDTO
                    {
                        Email   = model.ManagerEmail,
                        Name    = model.ManagerName,
                        Surname = model.ManagerSurname
                    };
                    Result <CompanyDetailDTO> result = await _companyService.AddCompanyAsync(companyDetailDTO, manager);

                    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));
                }
            }
            return(this.View((object)model));
        }
示例#4
0
        public async Task <IActionResult> Update(int id, CompanyFormModel model)
        {
            if (base.CurrentUser.Role != UserRole.SuperAdmin && base.CurrentUser.CompanyId != id)
            {
                return(this.RedirectToAction("Index", "Manage"));
            }
            model.IsUpdate = true;
            if (this.ModelState.IsValid)
            {
                try
                {
                    CompanyDetailDTO company  = Mapper.Map <CompanyFormModel, CompanyDetailDTO>(model);
                    IFormFile        logoFile = model.LogoFile;
                    if (logoFile != null)
                    {
                        string uniqueFileName = FileHelper.GetUniqueFileName(logoFile.FileName);
                        if (string.IsNullOrWhiteSpace(_hostingEnvironment.WebRootPath))
                        {
                            _hostingEnvironment.WebRootPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot");
                        }
                        string path  = Path.Combine(_hostingEnvironment.WebRootPath, "admin/uploads");
                        string path2 = Path.Combine(path, uniqueFileName);
                        using (FileStream stream = new FileStream(path2, FileMode.Create))
                        {
                            await logoFile.CopyToAsync((Stream)stream, default(CancellationToken));
                        }
                        company.Image = uniqueFileName;
                        model.Image   = uniqueFileName;
                    }
                    Result result = await _companyService.UpdateCompanyAsync(id, company);

                    model.FormMessage = result.FormMessage;
                    model.IsSuccess   = result.IsSuccess;
                    if (model.IsSuccess)
                    {
                        model.FormMessage = "İşleminiz başarılı bir şekilde gerçekleştirildi.";
                    }

                    if (result.Messages != null && result.Messages.Any())
                    {
                        var temp = result.Messages.FirstOrDefault(x => string.Equals(x, "Demo", StringComparison.InvariantCultureIgnoreCase));
                        if (temp != null)
                        {
                            using (yetkilimDBContext db = new yetkilimDBContext())
                            {
                                var listMail = new List <string>();

                                //var userPlaces = db.PanelUser.AsNoTracking().Where(x => x.PlaceId == feedback.PlaceId).ToList();
                                //if (userPlaces != null && userPlaces.Any())
                                //{
                                //    listMail.AddRange(userPlaces.Where(x => !string.IsNullOrWhiteSpace(x.Email)).Select(x => x.Email));
                                //}

                                //var place = db.Places.First(x => x.Id == feedback.PlaceId);

                                var userCompanies = db.PanelUser.Where(x => x.CompanyId == id && !x.IsDeleted).ToList();

                                for (int i = 0; i < userCompanies.Count; i++)
                                {
                                    try
                                    {
                                        string pass = PasswordHelper.GeneratePassword(6);
                                        userCompanies[i].Password        = PasswordHelper.MD5Hash(pass);
                                        db.Entry(userCompanies[i]).State = EntityState.Modified;
                                        db.SaveChanges();
                                        await _emailSender.Send(new string[] { userCompanies[i].Email }, "Yeni şireniz", pass);
                                    }
                                    catch (Exception ex)
                                    {
                                    }
                                }


                                // if (userCompanies != null && userCompanies.Any())
                                // {
                                //     listMail.AddRange(userCompanies.Where(x => !string.IsNullOrWhiteSpace(x.Email)).Select(x => x.Email));
                                // }

                                // foreach (var item in listMail)
                                // {
                                //     ;
                                // }
                            }
                        }
                    }


                    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));
        }