Example #1
0
        public override async Task <StoreResponse> AddStore(StoreRequest request, ServerCallContext context)
        {
            if (!Guid.TryParse(request.Store.Id, out Guid id))
            {
                throw new ArgumentException($"invalid store id {request.Store.Id}");
            }

            var store = new Shared.DAL.Store
            {
                ID      = id,
                Name    = request.Store.Name,
                Address = request.Store.Address,
                Country = request.Store.Country,
                Created = request.Store.Created.ToDateTime()
            };
            var entry = await this.repo.AddStoreAsync(store);

            return(new StoreResponse
            {
                Stores =
                {
                    new Store
                    {
                        Id = entry.ID.ToString(),
                        Name = entry.Name,
                        Country = entry.Country,
                        Address = entry.Address,
                        Created = Timestamp.FromDateTime(entry.Created)
                    }
                }
            });
        }
Example #2
0
        public async Task <Response <CalculateResponse> > CalculateTotal(StoreRequest storeRequest, string role)
        {
            if (string.IsNullOrEmpty(role))
            {
                throw new ApiException(ErrorMessages.RoleCanNotBeEmpty);
            }

            if (storeRequest.Weigth <= 0 || storeRequest.Price <= 0)
            {
                throw new ApiException(ErrorMessages.WeightCanNotBeZero);
            }

            if (storeRequest.Discount > 100)
            {
                throw new ApiException(ErrorMessages.DiscountCanNotBe100);
            }

            if (storeRequest.Discount > 0 && role != Roles.Privileged.ToString())
            {
                throw new ApiException(ErrorMessages.NotAPrivilegedCustomer);
            }

            CalculateResponse calculateResponse = new CalculateResponse();

            // use automapper to map the objects here.
            calculateResponse.Price    = storeRequest.Price;
            calculateResponse.Weigth   = storeRequest.Weigth;
            calculateResponse.Discount = storeRequest.Discount;
            int totalAmount = storeRequest.Price * storeRequest.Weigth;

            calculateResponse.Total = totalAmount - (double)(totalAmount * storeRequest.Discount) / 100;
            return(new Response <CalculateResponse>(calculateResponse));
        }
Example #3
0
 public void Delete(StoreRequest store)
 {
     if (store.Id.HasValue)
     {
         _repository.DeleteStore(store.Id.Value);
     }
 }
        public async Task CalculateTotal_ShouldEqualTotal_Theory(double expectedTotal,
                                                                 StoreRequest storeRequest, string role)
        {
            var output = await _storeService.CalculateTotal(storeRequest, role);

            Assert.Equal(expectedTotal, output.Data.Total);
        }
Example #5
0
        private void RemoveCheckedStoresReq_Click(object sender, EventArgs e)
        {
            List <StoreRequest> removeList = new List <StoreRequest>();

            for (int i = 0; i < StoresReq.Items.Count; i++)
            {
                if (StoresReq.GetItemChecked(i))
                {
                    StoreRequest tempData = new StoreRequest();
                    tempData.RefactorString(StoresReq.Items[i].ToString());
                    removeList.Add(tempData);
                }
            }

            for (int i = 0; i < removeList.Count; i++)
            {
                bool DONE = controller.RejectStore(removeList[i].storeRequestID, removeList[i].storeData.ID);
                if (DONE)
                {
                    MessageBox.Show(removeList[i].ToString() + " Removed");
                }
                else
                {
                    MessageBox.Show(removeList[i].ToString() + " Remove Failed");
                }
            }

            ShowReq_Click(sender, e);
        }
Example #6
0
        private void AddCheckedStoresReq_Click(object sender, EventArgs e)
        {
            List <StoreRequest> addList = new List <StoreRequest>();

            for (int i = 0; i < StoresReq.Items.Count; i++)
            {
                if (StoresReq.GetItemChecked(i))
                {
                    StoreRequest tempData = new StoreRequest();
                    tempData.RefactorString(StoresReq.Items[i].ToString());
                    addList.Add(tempData);
                }
            }

            for (int i = 0; i < addList.Count; i++)
            {
                bool DONE = controller.AcceptStore(addList[i].storeRequestID, addList[i].userID, addList[i].storeData.ID);
                if (DONE)
                {
                    MessageBox.Show(addList[i].ToString() + " Added");
                }
                else
                {
                    MessageBox.Show(addList[i].ToString() + " Add Failed");
                }
            }

            ShowReq_Click(sender, e);
        }
Example #7
0
        public MessageViewModel Store(StoreRequest request)
        {
            var msg = new Event(EventType.Log, request.Message);

            Events.Insert(0, msg);
            return(new MessageViewModel(msg));
        }
Example #8
0
        public void Store()
        {
            var request      = new StoreRequest();
            var newAttribute = new AttributeValues(incrementingAttribute,
                                                   "val" + (incrementingAttributeValue++).ToString(),
                                                   "val" + (incrementingAttributeValue++).ToString()
                                                   );

            request.AddAttribute(newAttribute);

            var response = ParameterizedTest <StoreResponse>(
                TestSupport.Scenarios.ExtensionFullCooperation, Version, request);

            Assert.IsNotNull(response);
            Assert.IsTrue(response.Succeeded);
            Assert.IsNull(response.FailureReason);

            var fetchRequest = new FetchRequest();

            fetchRequest.AddAttribute(new AttributeRequest {
                TypeUri = incrementingAttribute
            });
            var fetchResponse = ParameterizedTest <FetchResponse>(
                TestSupport.Scenarios.ExtensionFullCooperation, Version, fetchRequest);

            Assert.IsNotNull(fetchResponse);
            var att = fetchResponse.GetAttribute(incrementingAttribute);

            Assert.IsNotNull(att);
            Assert.AreEqual(newAttribute.Values.Count, att.Values.Count);
            for (int i = 0; i < newAttribute.Values.Count; i++)
            {
                Assert.AreEqual(newAttribute.Values[i], att.Values[i]);
            }
        }
Example #9
0
        public void AddAttributeByValue()
        {
            var             req   = new StoreRequest();
            AttributeValues value = new AttributeValues();

            req.Attributes.Add(value);
            Assert.AreSame(value, req.Attributes.Single());
        }
Example #10
0
        public async Task <IActionResult> AddStore([FromBody] StoreRequest request)
        {
            // var address = await db.Addresses
            //     .Include(a => a.Locality)
            //     .FirstOrDefaultAsync(a => a.Locality.Name == request.address.locality
            //                               && a.Street == request.address.street
            //                               && a.Building == request.address.building
            //                               && a.Apartment == request.address.apartment
            //                               && a.Entrance == request.address.entrance
            //                               && a.Level == request.address.level);
            //
            // if (address == null)
            // {
            //     address = new Address
            //     {
            //         Locality = db.Localities.FirstOrDefault(l => l.Name == request.address.locality),
            //         Street = request.address.street,
            //         Building = request.address.building,
            //         Apartment = request.address.apartment,
            //         Entrance = request.address.entrance,
            //         Level = request.address.level
            //     };
            //     await db.AddAsync(address);
            //     await db.SaveChangesAsync();
            // }

            var categories = db.CategoryStores
                             .Where(cs => request.categories.Contains(cs.Title))
                             .Select(c => c.Id);

            var store = new Store
            {
                Title        = request.title,
                BeginWorking = TimeSpan.FromHours(10),
                EndWorking   = TimeSpan.FromHours(20),
                AddressId    = request.address_id,
                StoreStatus  = db.StoreStatuses.FirstOrDefault(s => s.Name == "Рассматривается"),
                OwnerLogin   = User.Identity?.Name
            };

            await db.Stores.AddAsync(store);

            await db.SaveChangesAsync();

            foreach (var categoryId in categories)
            {
                await db.StoreCategories.AddAsync(new StoreCategory
                {
                    StoreId    = store.Id,
                    CategoryId = categoryId
                });
            }

            await db.SaveChangesAsync();

            return(Ok());
        }
Example #11
0
 /// <summary>
 /// 存储缓存
 /// </summary>
 /// <param name="code">存储方式</param>
 /// <param name="key">键值</param>
 /// <param name="value">缓存对象(需要可序列化)</param>
 /// <param name="expiry">缓存时长,0秒表示永久</param>
 /// <param name="cas">版本号(0表示忽略)</param>
 /// <exception cref="SocketException"></exception>
 /// <returns></returns>
 private OprationStatus Store(OpCodes code, string key, object value, TimeSpan expiry, long cas = 0)
 {
     return(this.Request <OprationStatus>(client =>
     {
         var valueBytes = client.ToBinary(value);
         var request = new StoreRequest(code, key, valueBytes, expiry, cas);
         return client.Send(request).Status;
     }));
 }
        protected override BinaryRequest CreateRequest()
        {
            var request = new StoreRequest(Allocator, operations[(int)Mode], Value, Expires)
            {
                Key = Key,
                Cas = Cas
            };

            return(request);
        }
        /// <summary>
        /// Validates an <see cref="StoreRequest"/>.
        /// </summary>
        /// <param name="request">The request to validate.</param>
        /// <exception cref="BadRequestException">Thrown when request body is missing.</exception>
        /// <exception cref="UidValidation">Thrown when the specified StudyInstanceUID is not a valid identifier.</exception>
        // TODO cleanup this method with Unit tests #72595
        public static void ValidateRequest(StoreRequest request)
        {
            EnsureArg.IsNotNull(request, nameof(request));
            if (request.RequestBody == null)
            {
                throw new BadRequestException(DicomCoreResource.MissingRequestBody);
            }

            UidValidation.Validate(request.StudyInstanceUid, nameof(request.StudyInstanceUid), allowEmpty: true);
        }
Example #14
0
 IKRequest <TNodeId> Decode(IKMessageContext <TNodeId> context, Request message)
 {
     return(message.Body switch
     {
         PingRequest ping => new KRequest <TNodeId, KPingRequest <TNodeId> >(Decode(context, message.Header), Decode(context, ping)),
         StoreRequest store => new KRequest <TNodeId, KStoreRequest <TNodeId> >(Decode(context, message.Header), Decode(context, store)),
         FindNodeRequest findNode => new KRequest <TNodeId, KFindNodeRequest <TNodeId> >(Decode(context, message.Header), Decode(context, findNode)),
         FindValueRequest findValue => new KRequest <TNodeId, KFindValueRequest <TNodeId> >(Decode(context, message.Header), Decode(context, findValue)),
         _ => throw new InvalidOperationException(),
     });
Example #15
0
        public void AddAttributeByPrimitives()
        {
            var req = new StoreRequest();

            req.Attributes.Add("http://att1", "value1", "value2");
            AttributeValues value = req.Attributes.Single();

            Assert.AreEqual("http://att1", value.TypeUri);
            Assert.IsTrue(MessagingUtilities.AreEquivalent(new[] { "value1", "value2" }, value.Values));
        }
        /// <summary>
        /// Validates an <see cref="StoreRequest"/>.
        /// </summary>
        /// <param name="request">The request to validate.</param>
        /// <exception cref="BadRequestException">Thrown when request body is missing.</exception>
        /// <exception cref="UidValidator">Thrown when the specified StudyInstanceUID is not a valid identifier.</exception>
        // TODO cleanup this method with Unit tests #72595
        public static void ValidateRequest(StoreRequest request)
        {
            if (request.RequestBody == null)
            {
                throw new BadRequestException(DicomCoreResource.MissingRequestBody);
            }

            if (request.StudyInstanceUid != null)
            {
                DicomElementMinimumValidation.ValidateUI(request.StudyInstanceUid, nameof(request.StudyInstanceUid));
            }
        }
        private void SendCanceledEmail()
        {
            StoreRequest thisRequest = _presenter.CurrentStoreRequest;

            //To the requester
            EmailSender.Send(_presenter.GetUser(thisRequest.Requester).Email, "Store Request Canceled", " Your Store Request with Request No. " + thisRequest.RequestNo + " was Canceled!");
            //To the approvers
            foreach (StoreRequestStatus statuses in thisRequest.StoreRequestStatuses)
            {
                EmailSender.Send(_presenter.GetUser(statuses.Approver).Email, "Store  Request Canceled", " The Store  Request with Request No. " + thisRequest.RequestNo + " has been Canceled!");
            }
        }
Example #18
0
        public async Task <ActionResult> LogOn()
        {
            var response = await RP.GetResponseAsync(this.Request, this.Response.ClientDisconnectedToken);

            if (response == null)
            {
                Session["customidentity"] = null;
                var request = await RP.CreateRequestAsync(EndPoint);

                StoreRequest store = new StoreRequest();
                store.Attributes.Add(new AttributeValues(Util.GetRootedUri("").ToString(), new[] { Session.SessionID }));
                request.AddExtension(store);
                var redirecting = await request.GetRedirectingResponseAsync(this.Response.ClientDisconnectedToken);

                //设置本地响应头部信息
                Response.ContentType = redirecting.Content.Headers.ContentType.ToString();
                return(redirecting.AsActionResult());
            }

            switch (response.Status)
            {
            case AuthenticationStatus.Authenticated:

                var fetch = response.GetExtension <FetchResponse>();

                var dic = fetch.Attributes.Where(obj =>
                {
                    return(obj.TypeUri.IndexOf(EndPoint) == 0);
                }).Select(obj => new { name = obj.TypeUri.Replace(EndPoint, ""), value = obj.Values[0] })
                          .ToLookup(obj => obj.name).ToDictionary(obj => obj.Key, obj => obj.First().value);

                UserModel user = null;
                if (!dic.Any(obj => string.IsNullOrEmpty(obj.Value)))
                {
                    user = new UserModel
                    {
                        UserName = dic["username"],
                        Email    = dic["email"],
                        Gender   = dic["gender"][0]
                    };
                }
                this._formsAuth.SignIn(user);
                return(this.RedirectToAction("index", "home"));

            case AuthenticationStatus.Canceled:
                break;

            case AuthenticationStatus.Failed:
                break;
            }

            return(new EmptyResult());
        }
 public async Task CalculateTotal_Error_Theory(string Expected,
                                               StoreRequest storeRequest, string role)
 {
     try
     {
         var output = await _storeService.CalculateTotal(storeRequest, role);
     }
     catch (ApiException ex)
     {
         Assert.Equal(Expected, ex.Message);
     }
 }
Example #20
0
        /// <summary>
        /// 获取店铺信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public ExecuteResult <StoreInfoResponse> GetStore(StoreRequest request)
        {
            var entity   = _storeRepsitory.GetItem(request.StoreId);
            var response = MappingManager.StoreResponseMapping(entity);


            var result = new ExecuteResult <StoreInfoResponse>
            {
                Data = response
            };

            return(result);
        }
        public Task <object> HandleStoreAsync(StoreRequest message)
        {
            switch (message.Store)
            {
            case "list":
                return(List(message.User));

            case "save":
                return(Save(message.User, message.Text));

            default: throw new NotImplementedException();
            }
        }
Example #22
0
        public IHttpActionResult GetList([FromUri] StoreRequest request, [UserProfile] UserProfile userProfile)
        {
            if (request == null)
            {
                request = new StoreRequest();
            }
            request.ArrangeParams();
            request.DataStoreIds = userProfile.StoreIds == null ? null : userProfile.StoreIds.ToList();

            var dto = _service.GetPagedList(request);

            return(RetrunHttpActionResult(dto));
        }
Example #23
0
        public virtual async Task <IHttpActionResult> GetStore(StoreRequest request)
        {
            var baseUrl = RequestUtils.GetBaseUrl(Request).ToString();
            var vm      = await StoreViewService.GetStoreViewModelAsync(new GetStoreByNumberParam
            {
                BaseUrl     = baseUrl,
                CultureInfo = ComposerContext.CultureInfo,
                Scope       = ComposerContext.Scope,
                StoreNumber = request.StoreNumber
            });

            return(Ok(vm));
        }
Example #24
0
        protected void grvIssueDetails_SelectedIndexChanged(object sender, EventArgs e)
        {
            int issueDetailId = Convert.ToInt32(grvIssueDetails.SelectedDataKey.Value);

            Session["IssueDetailId"] = issueDetailId;
            Session["detailIndex"]   = grvIssueDetails.SelectedIndex;
            IssueDetail theIssueDetail;

            if (issueDetailId > 0)
            {
                theIssueDetail = _presenter.CurrentIssue.GetIssueDetail(issueDetailId);
            }
            else
            {
                theIssueDetail = _presenter.CurrentIssue.IssueDetails[grvIssueDetails.SelectedIndex];
            }

            if (theIssueDetail.Item.ItemType == "Fixed Asset")
            {
                int storeReqId = Convert.ToInt32(Request.QueryString["StoreReqId"]);
                if (storeReqId != 0)
                {
                    StoreRequest storeReq = _presenter.GetStoreRequest(storeReqId);
                    PopFixedAsset(theIssueDetail.Item.Id, storeReq.Program.Id);
                }
                ScriptManager.RegisterStartupScript(this, GetType(), "showFixedAssetModal", "showFixedAssetModal();", true);
            }
            else
            {
                if (theIssueDetail.Store != null && theIssueDetail.Section != null && theIssueDetail.Shelf != null)
                {
                    int storeId   = theIssueDetail.Store.Id;
                    int sectionId = theIssueDetail.Section.Id;
                    int shelfId   = theIssueDetail.Shelf.Id;

                    ddlStore.SelectedValue = storeId.ToString();
                    PopSections(storeId);
                    ddlSection.SelectedValue = sectionId.ToString();
                    PopShelves(sectionId);
                    ddlShelf.SelectedValue = shelfId.ToString();
                }


                txtQuantity.Text = theIssueDetail.Quantity.ToString();
                txtUnitCost.Text = theIssueDetail.UnitCost.ToString();
                txtRemark.Text   = theIssueDetail.Remark;
                ddlCurAssetCustodian.SelectedValue = theIssueDetail.Custodian;

                ScriptManager.RegisterStartupScript(this, GetType(), "showDetailModal", "showDetailModal();", true);
            }
        }
        public ActionResult Edit([FromBody] StoreRequest request)
        {
            var store = request.Store;

            _context.Entry(store).State = EntityState.Modified;
            _context.SaveChanges();

            var format = request.TableFormat;

            return(Ok(new Message(true,
                                  "Success",
                                  GetStores(format.TableSize, format.SortColumn, format.Asc, format.CurrentPage)
                                  )));
        }
Example #26
0
        public void TestMethod1()
        {
            //把 AntiApi.WebAPI,部署在iis上,端口号是8070,即可测试调用
            //如果要修改配置Labels_Secret,需要同步修改接口TimingActionFilter.cs的secret

            StoreRequest storeRequest = new StoreRequest()
            {
                StoreName = "店铺1", UserNo = "1001"
            };

            var postData = JsonConvert.SerializeObject(storeRequest);

            var result = SendAPI("http://localhost:8070", "/api/Data/TestAPI", postData);
        }
Example #27
0
        public async Task <Store> AddAsync(StoreRequest request)
        {
            if (await _repository.Find(request.StoreName, request.Address) != null)
            {
                throw new ApiException("Store at given address with given name is already existing!");
            }
            var store = _mapper.Map <Store>(request);

            var addedStore = await _repository.Add(store);

            await _repository.SaveChangesAsync();

            return(addedStore);
        }
        public ActionResult Create([FromBody] StoreRequest request)
        {
            var store = request.Store;

            _context.Store.Add(store);
            _context.SaveChanges();

            var format = request.TableFormat;

            return(Ok(new Message(true,
                                  "Success",
                                  GetStores(format.TableSize, format.SortColumn, format.Asc, format.CurrentPage)
                                  )));
        }
Example #29
0
        public void Store(IEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            var request = new StoreRequest(entity.Clone(), GetLastWriteTime(entity.Path));

            lock (_requests)
            {
                _requests[entity.Path] = request;
            }
        }
Example #30
0
        public void Serializable()
        {
            var store = new StoreRequest();

            store.Attributes.Add("http://someAttribute", "val1", "val2");
            var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            var ms        = new MemoryStream();

            formatter.Serialize(ms, store);
            ms.Position = 0;
            var store2 = formatter.Deserialize(ms);

            Assert.AreEqual(store, store2);
        }
    public void storeVia(string NameSpace, Usage_Code_Point codePoint, int type, string[] args) {

      StoreRequest req = new StoreRequest(machine, codePoint, type, args);

      if (gateWayCache.ContainsKey(NameSpace) == true) {
        req.fire(NameSpace, gateWayCache[NameSpace]);
      }
      else {
        RequestQueue[NameSpace].Enqueue(req);
        ReDiRNode.lookupService(NameSpace);
      }
    }