public async Task <Result <TaggedUPC> > Insert(TaggedUPC taggedUPC, UPCHistory upcHistory)
        {
            try
            {
                _dbContext.Add <TaggedUPC>(taggedUPC);
                //_dbContext.Add<UPCHistory>(upcHistory);
                var result = await _dbContext.SaveChangesAsync();

                if (result <= 0)
                {
                    return(Result.Fail <TaggedUPC>(Constants.No_Rows_Added));
                }
                return(Result.Ok(taggedUPC));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#2
0
        public async Task <Result> ApprovedSavedUPC(int[] untaggedUPCIDs, int currentUserID)
        {
            if (untaggedUPCIDs.Length <= 0)
            {
                return(Result.Fail(Constants.SaveUPC_Group_To_Be_Approved_Are_Empty));
            }
            foreach (var i in untaggedUPCIDs)
            {
                var untaggedUPC = await _untaggedUPCRepo.GetUntaggedUPCOnID(i);

                if (untaggedUPC.IsSuccessed)
                {
                    var       u         = untaggedUPC.Value;
                    TaggedUPC taggedUPC = new TaggedUPC();
                    taggedUPC.UPCCode            = u.UPCCode;
                    taggedUPC.Description        = u.Description;
                    taggedUPC.DescriptionID      = u.DescriptionID;
                    taggedUPC.ProductSizing      = u.ProductSizing;
                    taggedUPC.ProductType        = ObjectMapper.CreateMap(u.ProductType);
                    taggedUPC.ProductCategory    = ObjectMapper.CreateMap(u.ProductCategory);
                    taggedUPC.ProductSubCategory = ObjectMapper.CreateMap(u.ProductSubCategory);

                    taggedUPC.IsMigrated = false;

                    UPCHistory upcHistory = new UPCHistory();
                    upcHistory.ApprovedBy     = currentUserID;
                    upcHistory.ItemInsertedAt = DateTime.UtcNow;
                    upcHistory.SubmittedBy    = u.ItemAssignedTo?.UserID;
                    upcHistory.TaggedUPCCode  = u.UPCCode;

                    await _taggedUPCService.InsertTaggedUPC(taggedUPC, upcHistory);

                    await _untaggedUPCRepo.Delete(i);
                }
                else
                {
                    continue;
                }
            }
            return(Result.Ok());
        }
        public async Task <Result> InsertTaggedUPC(TaggedUPC taggedUPC, UPCHistory upcHistory)
        {
            try
            {
                var taggedUPCRepo  = ObjectMapper.CreateMap(taggedUPC);
                var upcHistoryRepo = ObjectMapper.CreateMap(upcHistory);
                //taggedUPCRepo.UPCHistroy = upcHistoryRepo;

                var result = await _taggedUPCRepo.Insert(taggedUPCRepo, upcHistoryRepo);

                if (result.IsSuccessed)
                {
                    return(Result.Ok());
                }
                return(Result.Fail(result.GetErrorString()));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }