示例#1
0
        public async Task <PartialViewResult> CreateOrUpdateModal(long?id = null)
        {
            IContactAppService     contactAppService = this._contactAppService;
            NullableIdInput <long> nullableIdInput   = new NullableIdInput <long>()
            {
                Id = id
            };
            GetContactForEditOutput contactForEdit = await contactAppService.GetContactForEdit(nullableIdInput);

            return(this.PartialView("_CreateOrUpdateModal", new CreateOrUpdateContactModalViewModel(contactForEdit)));
        }
示例#2
0
        public virtual async Task <JsonResult> UpdateContactImage(long contactId)
        {
            JsonResult jsonResult;
            Guid?      imageId;

            try
            {
                if (this.Request.Files.Count <= 0 || this.Request.Files[0] == null)
                {
                    throw new UserFriendlyException(this.L("ContactImage_Change_Error"));
                }
                HttpPostedFileBase item = this.Request.Files[0];
                if (item.ContentLength > 512000)
                {
                    throw new UserFriendlyException(this.L("ContactImage_Warn_SizeLimit"));
                }
                GetContactForEditOutput contactForEdit = await this._contactAppService.GetContactForEdit(new NullableIdInput <long>(new long?(contactId)));

                GetContactForEditOutput nullable = contactForEdit;
                if (nullable.Contact.ImageId.HasValue)
                {
                    IBinaryObjectManager binaryObjectManager = this._binaryObjectManager;
                    imageId = nullable.Contact.ImageId;
                    await binaryObjectManager.DeleteAsync(imageId.Value);
                }
                BinaryObject binaryObject = new BinaryObject(item.InputStream.GetAllBytes());
                await this._binaryObjectManager.SaveAsync(binaryObject);

                nullable.Contact.ImageId = new Guid?(binaryObject.Id);
                UpdateContactImageInput updateContactImageInput = new UpdateContactImageInput()
                {
                    ContactId = nullable.Contact.Id.Value
                };
                imageId = nullable.Contact.ImageId;
                updateContactImageInput.ImageId = new Guid?(imageId.Value);
                await this._contactAppService.SaveContactImageAsync(updateContactImageInput);

                jsonResult = this.Json(new MvcAjaxResponse());
            }
            catch (UserFriendlyException userFriendlyException1)
            {
                UserFriendlyException userFriendlyException = userFriendlyException1;
                jsonResult = this.Json(new MvcAjaxResponse(new ErrorInfo(userFriendlyException.Message), false));
            }
            return(jsonResult);
        }
        /// <summary>
        /// 通过Id获取企业联系表信息进行编辑或修改
        /// </summary>
        public async Task <GetContactForEditOutput> GetContactForEditAsync(NullableIdDto <int> input)
        {
            var output = new GetContactForEditOutput();

            ContactEditDto contactEditDto;

            if (input.Id.HasValue)
            {
                var entity = await _contactRepository.GetAsync(input.Id.Value);

                contactEditDto = entity.MapTo <ContactEditDto>();
            }
            else
            {
                contactEditDto = new ContactEditDto();
            }

            output.Contact = contactEditDto;
            return(output);
        }
        public async Task <GetContactForEditOutput> GetContactForEdit(EntityDto input)
        {
            var contact = await _contactRepository.FirstOrDefaultAsync(input.Id);

            var output = new GetContactForEditOutput {
                Contact = ObjectMapper.Map <CreateOrEditContactDto>(contact)
            };

            if (output.Contact.UserId != null)
            {
                var _lookupUser = await _lookup_userRepository.FirstOrDefaultAsync((long)output.Contact.UserId);

                output.UserName = _lookupUser.Name.ToString();
            }

            if (output.Contact.VendorId != null)
            {
                var _lookupVendor = await _lookup_vendorRepository.FirstOrDefaultAsync((int)output.Contact.VendorId);

                output.VendorName = _lookupVendor.Name.ToString();
            }

            if (output.Contact.AssetOwnerId != null)
            {
                var _lookupAssetOwner = await _lookup_assetOwnerRepository.FirstOrDefaultAsync((int)output.Contact.AssetOwnerId);

                output.AssetOwnerName = _lookupAssetOwner.Name.ToString();
            }

            if (output.Contact.CustomerId != null)
            {
                var _lookupCustomer = await _lookup_customerRepository.FirstOrDefaultAsync((int)output.Contact.CustomerId);

                output.CustomerName = _lookupCustomer.Name.ToString();
            }

            return(output);
        }
 public CreateOrUpdateContactModalViewModel(GetContactForEditOutput output)
 {
     output.MapTo <GetContactForEditOutput, CreateOrUpdateContactModalViewModel>(this);
 }