public async Task <bool> UpdateAsync(CompanyEditModel model)
        {
            if (model == null)
            {
                return(ToResponse(false, Errors.invalid_data));
            }
            var company = _mapper.Map <CompanySql>(model);
            var result  = await _rpCompany.UpdateAsync(company, _process.User.Id);

            if (result.success)
            {
                if (!string.IsNullOrWhiteSpace(model.LastNote))
                {
                    var note = new NoteAddModel
                    {
                        Content       = model.LastNote,
                        ProfileId     = model.Id,
                        ProfileTypeId = (int)NoteType.Company,
                        UserId        = _process.User.Id
                    };
                    await _rpNote.AddNoteAsync(note);
                }
            }


            return(ToResponse(result));
        }
Exemple #2
0
        public async Task <IActionResult> Edit(int id, CompanyEditModel companyModel)
        {
            if (id != companyModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var userId = _userManager.GetUserId(User);
                    companyModel.ModifiedBy   = userId;
                    companyModel.ModifiedDate = DateTime.Now;
                    var company = BuildCompanyModel(companyModel);
                    _context.Update(company);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CompanyExists(companyModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(companyModel));
        }
Exemple #3
0
        private CompanyEditModel CreateFrom(Company entity)
        {
            var companyeditModel = new CompanyEditModel();

            //{
            companyeditModel.CompanyId    = entity.CompanyID;
            companyeditModel.CompanyName  = entity.CompanyName;
            companyeditModel.CompanyNo    = string.IsNullOrEmpty(entity.CompanyNo) ? "" : entity.CompanyNo;
            companyeditModel.EmailAddress = string.IsNullOrEmpty(entity.EmailAddress) ? "emailEmpty" : entity.EmailAddress;

            companyeditModel.Logo                       = entity.Logo == null ? "" : entity.Logo.ToString();
            companyeditModel.Telephone                  = string.IsNullOrEmpty(entity.Telephone) ? "" : entity.Telephone;
            companyeditModel.FaxNo                      = string.IsNullOrEmpty(entity.FaxNo) ? "" : entity.FaxNo;
            companyeditModel.Website                    = string.IsNullOrEmpty(entity.Website) ? "" : entity.Website;
            companyeditModel.InvoiceInfo                = string.IsNullOrEmpty(entity.InvoiceInfo) ? "" : entity.InvoiceInfo;
            companyeditModel.IsActive                   = entity.IsActive ?? false;
            companyeditModel.RelatedCompanyId           = entity.ParentCompany != null ? entity.ParentCompany.CompanyID : Guid.Empty;
            companyeditModel.RelatedCompanyName         = entity.ParentCompany != null ? entity.ParentCompany.CompanyName : string.Empty;
            companyeditModel.RelatedAddressId           = entity.Address != null ? entity.Address.AddressID : Guid.Empty;
            companyeditModel.RelatedRegisteredAddressId = entity.RegisteredAddress != null ? entity.RegisteredAddress.AddressID : Guid.Empty;
            //companyeditModel.UpdatedBy = string.IsNullOrEmpty(entity.UpdatedBy) ? "" : entity.UpdatedBy;
            companyeditModel.UpdatedDate = DateTime.Now;
            //companyeditModel.CreatedBy = string.IsNullOrEmpty(entity.CreatedBy) ? "" : entity.CreatedBy;
            companyeditModel.CreatedDate = DateTime.Now;
            //
            return(companyeditModel);
        }
        public async Task <IActionResult> EditCompany(CompanyEditModel values, int id, List <IFormFile> logo)
        {
            if (ModelState.IsValid)
            {
                IFormFile f = logo.FirstOrDefault();
                if (f.Length > 0)
                {
                    if (IsImage(f))
                    {
                        byte[] imageData = null;
                        using (var binary = new MemoryStream())
                        {
                            await f.CopyToAsync(binary);

                            imageData = binary.ToArray();
                        }
                        var kp = new Company
                        {
                            Id             = id,
                            name           = values.name,
                            email          = values.email,
                            PhoneNumber    = values.PhoneNumber,
                            Address        = values.Address,
                            companyCreated = DateTime.Parse(values.companyCreated),
                            Logo           = imageData
                        };
                        CompanyRepository.Update(kp);
                        CompanyRepository.Commit();

                        return(RedirectToAction("ViewCompany"));
                    }
                }
            }
            return(View());
        }
        public async Task <IActionResult> CreateCompany(CompanyEditModel values, List <IFormFile> logo)
        {
            if (ModelState.IsValid)
            {
                var comp = CompanyRepository.GetAll().LongCount();
                int len  = (int)comp;
                if (len >= 1)
                {
                    //cmpany exist
                    ViewBag.CompanyExist = "You Cannot Create More than one company account";
                }
                else
                {
                    IFormFile f = logo.FirstOrDefault();
                    if (f.Length > 0)
                    {
                        //check if an image is uploaded
                        if (IsImage(f))
                        {
                            byte[] imageData = null;
                            using (var binary = new MemoryStream())
                            {
                                await f.CopyToAsync(binary);

                                imageData = binary.ToArray();
                            }
                            Company k = new Company
                            {
                                name           = values.name,
                                email          = values.email,
                                PhoneNumber    = values.PhoneNumber,
                                Address        = values.Address,
                                Logo           = imageData,
                                companyCreated = DateTime.Now
                            };
                            CompanyRepository.Add(k);
                            CompanyRepository.Commit();

                            HttpContext.Session.SetString("CompanySuccess", "successfully created company's account");

                            return(RedirectToAction("CreateCompany"));
                        }
                        else
                        {
                            //not of the right format
                            ViewBag.NotRightFormat = "The image is not in the right format";
                        }
                    }
                    else
                    {
                        //no image is uploaded
                        ViewBag.noUpload = "You have not uploaded any image";
                    }
                }
            }
            return(View());
        }
Exemple #6
0
        public ActionResult Edit(CompanyEditModel model)
        {
            var company = db.Company.Find(model.Id);

            company.Name              = model.Name;
            company.CompanyScaleId    = model.ScaleId;
            company.CompanyTypeId     = model.TypeId;
            company.CompanyWorkLineId = model.WorklineId;
            db.SaveChanges();
            return(Ok());
        }
Exemple #7
0
        public CompanyEditModel UpdateCompany(CompanyEditModel model)
        {
            var company = ApplyChanges(model);

            company.ObjectState = ObjectState.Modified;

            company.UpdatedDate = DateTime.Now;
            _companyService.Update(company);
            _companyService.RefreshCache();
            return(model);
        }
Exemple #8
0
        public ActionResult Edit(long companyId, CompanyEditModel model)
        {
            try
            {
                manager.SaveEditModel(companyId, model);

                return(Ok());
            }
            catch (KeyNotFoundException)
            {
                return(NotFound());
            }
        }
Exemple #9
0
        public CompanyEditModel CreateCompany(CompanyEditModel model)
        {
            var company = ApplyChanges(model);

            company.ObjectState = ObjectState.Added;

            company.CreatedDate = DateTime.Now;
            company.IsActive    = true;
            _companyService.Insert(company);

            _companyService.RefreshCache();
            model.CompanyId = company.CompanyID;
            return(model);
        }
Exemple #10
0
        public virtual ActionResult Create()
        {
            var model = new CompanyEditModel()
            {
                BankAccount = new BankAccountEditModel(), Address = new AddressEditModel()
            };
            var currencies = _companies.GetAllCurrencies();

            model.BankAccount.Currencies = _mapper.Map <List <CurrencyViewModel> >(currencies);
            var countries = _companies.GetAllCountries();

            model.Address.Countries = _mapper.Map <List <CountryViewModel> >(countries);
            return(View(model));
        }
Exemple #11
0
        private CompanyEditModel BuildCompanyEditModel(Company company)
        {
            var model = new CompanyEditModel
            {
                Id           = company.Id,
                Code         = company.Code,
                Name         = company.Name,
                Status       = company.Status,
                CreatedBy    = company.CreatedBy != null ? company.CreatedBy.Id : string.Empty,
                CreatedDate  = company.CreationDate,
                ModifiedBy   = company.ModifiedBy != null ? company.ModifiedBy.Id : string.Empty,
                ModifiedDate = company.ModifiedDate != null || company.ModifiedDate != DateTime.MinValue ? (DateTime?)company.ModifiedDate : null
            };

            return(model);
        }
Exemple #12
0
        public async Task <IActionResult> Edit(CompanyEditModel inputModel)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(inputModel));
            }

            var result = await this.companyService.EditCompanyName(inputModel.Id, inputModel.Name);

            if (!result.Success)
            {
                return(this.View());
            }

            return(this.RedirectToAction(nameof(Details), new { id = result.Data.Id }));
        }
        public async Task <ResultData <CompanyEditModel> > CreateEditModel(int id)
        {
            Company company = await this.companyRepository.GetCompanyById(id);

            if (company == null)
            {
                return(new ResultData <CompanyEditModel>(CompanyNotFoundMessage, false, null));
            }

            CompanyEditModel model = new CompanyEditModel
            {
                Id   = company.Id,
                Name = company.Name
            };

            return(new ResultData <CompanyEditModel>(CompanyEditModelCreatedMessage, true, model));
        }
        public IdentityCompany ExtractEditFormData(CompanyEditModel formData)
        {
            var myIdentity = new IdentityCompany();

            myIdentity.Id         = formData.Id;
            myIdentity.Code       = formData.Code;
            myIdentity.Name       = formData.Name;
            myIdentity.CountryId  = formData.CountryId;
            myIdentity.ProvinceId = formData.ProvinceId;
            myIdentity.DistrictId = formData.DistrictId;
            myIdentity.Address    = formData.Address;
            myIdentity.Email      = formData.Email;
            myIdentity.Phone      = formData.Phone;
            myIdentity.IsEPE      = formData.IsEPE;
            myIdentity.Status     = formData.Status;

            return(myIdentity);
        }
Exemple #15
0
        private Company BuildCompanyModel(CompanyEditModel model)
        {
            var createdBy  = _userManager.FindByIdAsync(model.CreatedBy).Result;
            var modifiedBy = _userManager.FindByIdAsync(model.ModifiedBy).Result;
            var company    = new Company
            {
                Id           = model.Id,
                Code         = model.Code,
                Name         = model.Name,
                Status       = model.Status,
                CreatedBy    = createdBy,
                CreationDate = model.CreatedDate,
                ModifiedBy   = modifiedBy,
                ModifiedDate = (DateTime)model.ModifiedDate
            };

            return(company);
        }
        public async Task <IActionResult> EditCompanyModal(CompanyEditModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.Json(new { isValid = false, redirectToUrl = string.Empty, html = this.View(model) }));
            }

            try
            {
                await this.contactsService.EditCompanyAsync(model);
            }
            catch (Exception)
            {
                return(this.Json(new { isValid = false, redirectToUrl = "reload" }));
            }

            return(this.Json(new { isValid = true, redirectToUrl = "reload" }));
        }
        public IActionResult EditCompany(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("400"));
            }
            Company          comp = CompanyRepository.Get(id);
            CompanyEditModel po   = new CompanyEditModel()
            {
                name        = comp.name,
                email       = comp.email,
                PhoneNumber = comp.PhoneNumber,
                Address     = comp.Address,
                logo        = comp.Logo,
                Date        = comp.companyCreated.ToShortDateString(),
                Time        = comp.companyCreated.ToShortTimeString()
            };

            return(View(po));
        }
        public CompanyEditModel RenderEditModel(IdentityCompany identity)
        {
            var editModel = new CompanyEditModel();

            editModel.Code       = identity.Code;
            editModel.Name       = identity.Name;
            editModel.CountryId  = identity.CountryId;
            editModel.ProvinceId = identity.ProvinceId;
            editModel.DistrictId = identity.DistrictId;
            editModel.Countrys   = CommonHelpers.GetListCountry();
            editModel.Provinces  = CommonHelpers.GetProvinceByCountry(identity.CountryId);
            editModel.Districts  = CommonHelpers.GetDistrictByProvince(identity.ProvinceId);
            editModel.Address    = identity.Address;
            editModel.Email      = identity.Email;
            editModel.Phone      = identity.Phone;
            editModel.IsEPE      = identity.IsEPE;
            editModel.Status     = identity.Status;

            return(editModel);
        }
Exemple #19
0
        private Company ApplyChanges(CompanyEditModel model)
        {
            return(new Company
            {
                CompanyID = Guid.Empty != model.CompanyId ? model.CompanyId : PrimeActs.Service.IDGenerator.NewGuid(_serverCode.ToCharArray()[0]),
                CompanyName = model.CompanyName,

                EmailAddress = model.EmailAddress,
                Telephone = model.Telephone,
                FaxNo = model.FaxNo,
                Website = model.Website,
                InvoiceInfo = model.InvoiceInfo,
                IsActive = model.IsActive,

                UpdatedDate = model.UpdatedDate, //string.IsNullOrWhiteSpace(model.UpdatedDate) ? (DateTime?)null : DateTime.Parse(model.UpdatedDate),

                CreatedDate = model.CreatedDate, //string.IsNullOrWhiteSpace(model.CreatedDate) ? (DateTime?)null : DateTime.Parse(model.CreatedDate),
                RegisteredAddressID = model.RelatedRegisteredAddressId == Guid.Empty ? (Guid?)null : model.RelatedRegisteredAddressId,
                AddressID = model.RelatedAddressId == Guid.Empty ? (Guid?)null : model.RelatedAddressId,
                ParentCompanyID = model.RelatedCompanyId == Guid.Empty?(Guid?)null:model.RelatedCompanyId,
            });
        }
Exemple #20
0
        public async Task <string> EditCompanyAsync(CompanyEditModel input)
        {
            var company = this.companiesRepository.All().FirstOrDefault(c => c.Id == input.Id);

            if (company == null)
            {
                throw new ArgumentException("Company do not exist!");
            }

            company.Name      = input.Name;
            company.TaxNumber = input.TaxNumber;
            company.Address.Address.StreetLine = input.AddressAddressStreetLine;
            company.Address.MOLFirstName       = input.AddressMOLFirstName;
            company.Address.MOLLastName        = input.AddressMOLLastName;
            company.Comunicators.Mobile1       = input.ComunicatorsMobile1;
            company.Comunicators.Email1        = input.ComunicatorsEmail1;
            company.Comunicators.Details       = input.ComunicatorsDetails;

            await this.companiesRepository.SaveChangesAsync();

            return(company.Id);
        }
Exemple #21
0
        public virtual ActionResult Create(CompanyEditModel model)
        {
            var company = _mapper.Map <Company>(model);

            _companies.Add(company);
            _companies.Commit();
            CompanySearchViewModel searchCriteria = (CompanySearchViewModel)Session[Consts.SessionDataType.SEARCH_CRITERIA];

            if (searchCriteria == null)
            {
                searchCriteria = new CompanySearchViewModel()
                {
                    PageIndex    = 1,
                    PageSize     = 10,
                    SortByList   = Enums.CompanySortBy.Name.ToSelectList(),
                    SortTypeList = Enums.SortOrder.Ascending.ToSelectList()
                };
            }
            searchCriteria.InitSearch = true;

            return(View(MVC.Company.Views.Index, searchCriteria));
        }
        public ActionResult Edit(CompanyEditModel model)
        {
            if (!ModelState.IsValid)
            {
                string messages = string.Join("; ", ModelState.Values
                                              .SelectMany(x => x.Errors)
                                              .Select(x => x.ErrorMessage + x.Exception));
                this.AddNotification(messages, NotificationType.ERROR);
                return(View(model));
            }

            try
            {
                var info = ExtractEditFormData(model);

                var isSuccess = _mainStore.Update(info);

                //Clear cache
                CachingHelpers.ClearProductCache(info.Id);

                if (isSuccess)
                {
                    this.AddNotification(ManagerResource.LB_UPDATE_SUCCESS, NotificationType.SUCCESS);
                }
            }
            catch (Exception ex)
            {
                this.AddNotification(NotifSettings.Error_SystemBusy, NotificationType.ERROR);

                logger.Error("Failed for Edit Product request: " + ex.ToString());

                return(View(model));
            }

            return(RedirectToAction("Edit/" + model.Id));
        }
Exemple #23
0
 public void SaveEditModel(long id, CompanyEditModel model)
 {
 }
        public async Task <IActionResult> UpdateAsync([FromBody] CompanyEditModel model)
        {
            var result = await _bizCompany.UpdateAsync(model);

            return(ToResponse(result));
        }