Exemple #1
0
 public async Task <int> Update(string tenantId, string branchContactId, string languageId, BranchContactTranslation branchContactTranslation)
 {
     return(await Context.SaveChangesAsync());
 }
Exemple #2
0
        public async Task <ActionResultResponse> Update(string tenantId, string id, BranchContactMeta branchContactMeta)
        {
            if (!EnumerableExtensions.Any(branchContactMeta.BranchContactTranslations))
            {
                return(new ActionResultResponse(-1, _sharedResourceService.GetString("Please enter at least one language.")));
            }

            var branchContactInfo = await _branchContactRepository.GetInfo(id);

            if (branchContactInfo == null)
            {
                return(new ActionResultResponse(-2, _resourceService.GetString("BranchContact does not exists.")));
            }

            if (branchContactInfo.ConcurrencyStamp != branchContactMeta.ConcurrencyStamp)
            {
                return(new ActionResultResponse(-3, _resourceService.GetString("The BranchContact already updated by other people. You can not update this BranchContact.")));
            }

            branchContactInfo.LastUpdate       = DateTime.Now;
            branchContactInfo.ConcurrencyStamp = Guid.NewGuid().ToString();
            branchContactInfo.WorkTime         = branchContactMeta.WorkTime;
            branchContactInfo.Link             = branchContactMeta.Link;
            branchContactInfo.Order            = branchContactMeta.Order;
            branchContactInfo.Website          = branchContactMeta.Website;
            branchContactInfo.Logo             = branchContactMeta.Logo;
            branchContactInfo.IsOffice         = branchContactMeta.IsOffice;

            await _branchContactRepository.Update(id, branchContactInfo);

            foreach (var branchContactTranslation in branchContactMeta.BranchContactTranslations)
            {
                var branchContactTranslationInfo = await _branchContactTranslationRepository.GetInfo(tenantId, id, branchContactTranslation.LanguageId);

                if (branchContactTranslationInfo != null)
                {
                    branchContactTranslationInfo.Name       = branchContactTranslation.Name;
                    branchContactTranslationInfo.UnsignName = branchContactTranslation.Name.Trim().StripVietnameseChars().ToUpper();
                    branchContactTranslationInfo.Address    = branchContactTranslation.Address;
                    await _branchContactTranslationRepository.Update(tenantId, id, branchContactTranslation.LanguageId, branchContactTranslationInfo);
                }
                else
                {
                    branchContactTranslationInfo = new BranchContactTranslation()
                    {
                        Name            = branchContactTranslation.Name,
                        LanguageId      = branchContactTranslation.LanguageId,
                        TenantId        = tenantId,
                        Address         = branchContactTranslation.Address,
                        BranchContactId = branchContactInfo.Id,
                        UnsignName      = branchContactTranslation.Name.Trim().StripVietnameseChars().ToUpper()
                    };
                    await _branchContactTranslationRepository.Insert(branchContactTranslationInfo);
                }
            }

            var listBranchContactItem = await _branchContactDetailRepository.GetAll(id, true);

            if (listBranchContactItem != null && listBranchContactItem.Any())
            {
                foreach (var branchItem in listBranchContactItem)
                {
                    var branchItemExists = branchContactMeta.BranchContactDetails.Where(x => x.Id == branchItem.Id).ToList();
                    if (branchItemExists == null || branchItemExists.Count() == 0)
                    {
                        await _branchContactDetailRepository.ForceDelete(branchItem.Id);
                    }
                }
            }

            foreach (var branchContactDetail in branchContactMeta.BranchContactDetails)
            {
                var branchContactDetailInfo = await _branchContactDetailRepository.GetInfo(branchContactDetail.Id);

                if (branchContactDetailInfo != null)
                {
                    branchContactDetailInfo.ContactValue = branchContactDetail.ContactValue;
                    branchContactDetailInfo.ContactType  = branchContactDetail.ContactType;
                    await _branchContactDetailRepository.Update(branchContactDetail.Id, branchContactDetailInfo);
                }
                else
                {
                    branchContactDetailInfo = new BranchContactDetail()
                    {
                        Id = Guid.NewGuid().ToString(),
                        BranchContactId = branchContactInfo.Id,
                        ContactType     = branchContactDetail.ContactType,
                        ContactValue    = branchContactDetail.ContactValue,
                    };
                    await _branchContactDetailRepository.Insert(branchContactDetailInfo);
                }
            }

            return(new ActionResultResponse(1, _resourceService.GetString("Update BranchContact successful.")));
        }
Exemple #3
0
 public async Task <int> Insert(BranchContactTranslation branchContactTranslation)
 {
     _branchContactTranslationRepository.Create(branchContactTranslation);
     return(await Context.SaveChangesAsync());
 }