Exemplo n.º 1
0
        public override void Setup()
        {
            base.Setup();

            // Spin up mock repository and attach to controller
            MockService = new Mock<IPurchaseTypeService>();

            DefaultPurchaseType = new DeepBlue.Models.Entity.PurchaseType(MockService.Object);
            MockService.Setup(x => x.SavePurchaseType(It.IsAny<DeepBlue.Models.Entity.PurchaseType>()));
        }
Exemplo n.º 2
0
 public static List<DeepBlue.Models.Entity.PurchaseType> GetPurchaseTypesFromDeepBlue(CookieCollection cookies)
 {
     //
     List<DeepBlue.Models.Entity.PurchaseType> purchaseTypes = new List<DeepBlue.Models.Entity.PurchaseType>();
     // Send the request
     string url = HttpWebRequestUtil.GetUrl("Admin/PurchaseTypeList?pageIndex=1&pageSize=5000&sortName=Name&sortOrder=asc");
     HttpWebResponse response = HttpWebRequestUtil.SendRequest(url, null, false, cookies, false, HttpWebRequestUtil.JsonContentType);
     if (response.StatusCode == System.Net.HttpStatusCode.OK) {
         using (Stream receiveStream = response.GetResponseStream()) {
             // Pipes the stream to a higher level stream reader with the required encoding format.
             using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8)) {
                 string resp = readStream.ReadToEnd();
                 if (!string.IsNullOrEmpty(resp)) {
                     JavaScriptSerializer js = new JavaScriptSerializer();
                     FlexigridData flexiGrid = (FlexigridData)js.Deserialize(resp, typeof(FlexigridData));
                     foreach (Helpers.FlexigridRow row in flexiGrid.rows) {
                         DeepBlue.Models.Entity.PurchaseType purchaseType = new DeepBlue.Models.Entity.PurchaseType();
                         purchaseType.PurchaseTypeID = Convert.ToInt32(row.cell[0]);
                         purchaseType.Name = Convert.ToString(row.cell[1]);
                         purchaseTypes.Add(purchaseType);
                     }
                 }
                 else {
                 }
                 response.Close();
                 readStream.Close();
             }
         }
     }
     return purchaseTypes;
 }
Exemplo n.º 3
0
 private IEnumerable<ErrorInfo> Validate(PurchaseType purchaseType)
 {
     return ValidationHelper.Validate(purchaseType);
 }
Exemplo n.º 4
0
 public ActionResult UpdatePurchaseType(FormCollection collection)
 {
     EditPurchaseTypeModel model=new EditPurchaseTypeModel();
     ResultModel resultModel=new ResultModel();
     this.TryUpdateModel(model);
     string ErrorMessage=PurchaseTypeNameAvailable(model.Name,model.PurchaseTypeId);
     if(String.IsNullOrEmpty(ErrorMessage)==false) {
         ModelState.AddModelError("Name",ErrorMessage);
     }
     if(ModelState.IsValid) {
         PurchaseType purchaseType=AdminRepository.FindPurchaseType(model.PurchaseTypeId);
         if(purchaseType==null) {
             purchaseType=new PurchaseType();
         }
         purchaseType.Name=model.Name;
         purchaseType.EntityID=Authentication.CurrentEntity.EntityID;
         IEnumerable<ErrorInfo> errorInfo=AdminRepository.SavePurchaseType(purchaseType);
         if(errorInfo!=null) {
             resultModel.Result+=ValidationHelper.GetErrorInfo(errorInfo);
         } else {
             resultModel.Result="True||"+purchaseType.PurchaseTypeID;
         }
     } else {
         foreach(var values in ModelState.Values.ToList()) {
             foreach(var err in values.Errors.ToList()) {
                 if(string.IsNullOrEmpty(err.ErrorMessage)==false) {
                     resultModel.Result+=err.ErrorMessage+"\n";
                 }
             }
         }
     }
     return View("Result",resultModel);
 }