Exemplo n.º 1
0
        public void Should_UpdateAnnouncementSupplierTemplateListData()
        {
            var announcement = CreateAnnouncement();

            var model = new UpdateAnnouncementSupplierTemplateModel
            {
                AnnouncementTemplateSuppliersListTypeId = 1,
                BranchId      = BranchId,
                AgencyCode    = AgencyCode,
                AgencyAddress = AgencyAddress,
                AgencyFax     = AgencyFax,
                AgencyPhone   = AgencyPhone,
                AgencyEmail   = AgencyEmail
            };

            var name = "name";
            var fileNetReferenceId = "123";
            var attachmentType     = 1;

            var atta = new AnnouncementSuppliersTemplateAttachment(name, fileNetReferenceId, attachmentType);

            announcement.UpdateAnnouncementSupplierTemplateListData(
                model, new List <AnnouncementSuppliersTemplateAttachment>
            {
                atta
            },
                Cr);

            announcement.ShouldNotBeNull();
            announcement.IsEffectiveList.ShouldBe(true);
            announcement.EffectiveListDate.ShouldBeNull();
            announcement.BranchId.ShouldBe(BranchId);
            announcement.AgencyCode.ShouldBe(AgencyCode);
            announcement.AgencyAddress.ShouldBe(AgencyAddress);
            announcement.AgencyFax.ShouldBe(AgencyFax);
            announcement.AgencyPhone.ShouldBe(AgencyPhone);
            announcement.AgencyEmail.ShouldBe(AgencyEmail);

            announcement.Attachments.Count.ShouldBeGreaterThanOrEqualTo(1);
            announcement.Attachments[0].Name.ShouldBe(name);
        }
        private void IsValidToUpdate(UpdateAnnouncementSupplierTemplateModel announcement)
        {
            if (announcement.IsEffectiveList && announcement.EffectiveListDate == null)
            {
                throw new BusinessRuleException(Resources.AnnouncementResources.ErrorMessages.EffectiveListDateRequired);
            }

            if (announcement.IsEffectiveList && announcement.EffectiveListDate < DateTime.Now)
            {
                throw new BusinessRuleException(Resources.SharedResources.ErrorMessages.DateLessThanToday);
            }

            if (!announcement.IsEffectiveList)
            {
                announcement.EffectiveListDate = null;
            }

            if (string.IsNullOrEmpty(announcement.AgencyAddress) || string.IsNullOrEmpty(announcement.AgencyFax) || string.IsNullOrEmpty(announcement.AgencyPhone) || string.IsNullOrEmpty(announcement.AgencyEmail))
            {
                throw new BusinessRuleException(Resources.AnnouncementResources.ErrorMessages.AgencyRequired);
            }
        }
 public AnnouncementSupplierTemplate UpdateAnnouncementSupplierTemplateListData(UpdateAnnouncementSupplierTemplateModel model, List <AnnouncementSuppliersTemplateAttachment> attachments, int userId)
 {
     AnnouncementTemplateSuppliersListTypeId = model.AnnouncementTemplateSuppliersListTypeId;
     IsEffectiveList   = model.IsEffectiveList;
     EffectiveListDate = model.EffectiveListDate;
     BranchId          = model.BranchId;
     AgencyCode        = model.AgencyCode;
     AgencyAddress     = model.AgencyAddress;
     AgencyFax         = model.AgencyFax;
     AgencyPhone       = model.AgencyPhone;
     AgencyEmail       = model.AgencyEmail;
     UpdateSuppliersTemplateAttachments(attachments, userId, false);
     EntityUpdated();
     return(this);
 }
        public async Task <UpdateAnnouncementSupplierTemplateModel> UpdateAnnouncementSupplierTemplateList(UpdateAnnouncementSupplierTemplateModel announcementModel)
        {
            IsValidToUpdate(announcementModel);
            int createdById = _httpContextAccessor.HttpContext.User.UserId();

            Check.ArgumentNotNull(nameof(announcementModel), announcementModel);
            List <AnnouncementSuppliersTemplateAttachment> attachments = new List <AnnouncementSuppliersTemplateAttachment>();

            if (announcementModel.Attachments != null)
            {
                foreach (var item in announcementModel.Attachments)
                {
                    attachments.Add(new AnnouncementSuppliersTemplateAttachment(item.Name, item.FileNetReferenceId, item.AttachmentTypeId));
                }
            }
            var announcementSupplierTemplate = await _announcementQueries.GetAnnouncementByIdForCreationStep(Util.Decrypt(announcementModel.AnnouncementIdString));

            announcementSupplierTemplate.UpdateAnnouncementSupplierTemplateListData(announcementModel, attachments, createdById);
            await _announcementCommands.UpdateAnnouncementSupplierTemplate(announcementSupplierTemplate);

            await _announcementCommands.SaveChangesAsync();

            return(announcementModel);
        }
        public async Task <UpdateAnnouncementSupplierTemplateModel> UpdateAnnouncementSupplierTemplateList([FromBody] UpdateAnnouncementSupplierTemplateModel announcementModel)
        {
            var result = await _announcementSupplierTemplateAppService.UpdateAnnouncementSupplierTemplateList(announcementModel);

            return(result);
        }