Ejemplo n.º 1
0
        public async Task <IActionResult> Update(string id, [FromBody] SupplierMeta supplierMeta)
        {
            var result = await _supplierService.Update(id, CurrentUser.TenantId, CurrentUser.Id, CurrentUser.FullName, supplierMeta);

            if (result.Code <= 0)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
Ejemplo n.º 2
0
        public async Task <ActionResultResponse> Insert(string tenantId, string creatorId, string creatorFullName, SupplierMeta supplierMeta)
        {
            //if (!supplierMeta.Contacts.Any())
            //    return new ActionResultResponse(-1, _sharedResourceService.GetString("Please enter at least one contact."));

            var checkInfo = await _supplierRepository.CheckExistsByName(tenantId, null, supplierMeta.Name);

            if (checkInfo)
            {
                return(new ActionResultResponse(-1, _resourceService.GetString("Supplier name already exists.")));
            }

            var supplierId = Guid.NewGuid().ToString();
            var supplier   = new Supplier
            {
                Id               = supplierId,
                Name             = supplierMeta.Name,
                UnsignName       = supplierMeta.Name.StripVietnameseChars().ToUpper(),
                Description      = supplierMeta.Description,
                IsActive         = supplierMeta.IsActive,
                CreateTime       = DateTime.Now,
                ConcurrencyStamp = Guid.NewGuid().ToString(),
                Address          = supplierMeta.Address,
                TenantId         = tenantId,
                CreatorId        = creatorId,
                CreatorFullName  = creatorFullName,
            };

            var result = await _supplierRepository.Insert(supplier);

            if (result <= 0)
            {
                return(new ActionResultResponse(result, _sharedResourceService.GetString("Something went wrong. Please contact with administrator.")));
            }

            if (supplierMeta.Contacts != null && supplierMeta.Contacts.Any())
            {
                var contacts = new List <Contact>();
                foreach (var contact in supplierMeta.Contacts)
                {
                    contacts.Add(new Contact
                    {
                        Id               = Guid.NewGuid().ToString(),
                        SubjectId        = supplier.Id,
                        FullName         = contact.FullName,
                        PositionName     = contact.PositionName,
                        Email            = contact.Email,
                        Fax              = contact.Fax,
                        PhoneNumber      = contact.PhoneNumber,
                        Description      = contact.Description,
                        UnsignName       = contact.FullName.Trim().StripVietnameseChars().ToUpper(),
                        Status           = contact.Status,
                        ConcurrencyStamp = supplier.ConcurrencyStamp,
                        Type             = contact.Type,
                        CreatorId        = creatorId,
                        CreatorFullName  = creatorFullName,
                    });
                }

                if (contacts.Any())
                {
                    var resultInsertDetail = await _contactRepository.Inserts(contacts);

                    if (resultInsertDetail < 0)
                    {
                        await RollbackInsert(supplierId, tenantId);

                        return(new ActionResultResponse(-5, _resourceService.GetString("Can not insert new Supplier. Please contact with administrator.")));
                    }
                }
            }

            return(new ActionResultResponse(result, _sharedResourceService.GetString("Insert supplier success.")));
        }
Ejemplo n.º 3
0
        public async Task <ActionResultResponse> Update(string id, string tenantId, string lastUpdateUserId, string lastUpdateFullName, SupplierMeta supplierMeta)
        {
            //if (!supplierMeta.Contacts.Any())
            //    return new ActionResultResponse(-1, _sharedResourceService.GetString("Please enter at least one language."));
            var checkInfo = await _supplierRepository.CheckExistsByName(tenantId, id, supplierMeta.Name);

            if (checkInfo)
            {
                return(new ActionResultResponse(-1, _resourceService.GetString("Supplier name already exists.")));
            }

            var supplierInfo = await _supplierRepository.GetInfo(id, tenantId);

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

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

            supplierInfo.Name               = supplierMeta.Name;
            supplierInfo.UnsignName         = supplierMeta.Name.StripVietnameseChars().ToUpper();
            supplierInfo.Description        = supplierMeta.Description;
            supplierInfo.IsActive           = supplierMeta.IsActive;
            supplierInfo.ConcurrencyStamp   = Guid.NewGuid().ToString();
            supplierInfo.Address            = supplierMeta.Address;
            supplierInfo.LastUpdateUserId   = lastUpdateUserId;
            supplierInfo.LastUpdateFullName = lastUpdateFullName;
            supplierInfo.LastUpdateTime     = DateTime.Now;

            var result = await _supplierRepository.Update(supplierInfo);

            return(new ActionResultResponse(result, result <= 0 ? _resourceService.GetString("Something went wrong. Please contact with administrator.")
                  : _resourceService.GetString("Update Supplier successful.")));
        }