Ejemplo n.º 1
0
        public string AddNewSpotItem(TradeSharpConnection context, SpotModel model)
        {
            var result = string.Empty;
            var newContext = EnsureContext(ref context);
            try
            {
                var spot = new SPOT
                {
                    ComBase = model.ComBase,
                    ComCounter = model.ComCounter,
                    Title = model.Title,
                    CodeFXI = model.CodeFXI,
                    MinVolume = model.MinVolume,
                    MinStepVolume = model.MinStepVolume,
                    Precise = model.Precise,
                    SwapBuy = model.SwapBuy,
                    SwapSell = model.SwapSell,
                    Description = model.Description
                };

                context.SPOT.Add(spot);
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                Logger.Error("AddNewSpotItem()", ex);
                result = ex.Message;
            }
            finally
            {
                if (newContext != null) newContext.Dispose();
            }
            return result;
        }
Ejemplo n.º 2
0
        public string EditSpotItem(TradeSharpConnection context, SpotModel model)
        {
            var result = string.Empty;
            var newContext = EnsureContext(ref context);
            try
            {
                var itemToEdit = context.SPOT.Single(x => x.Title == model.Title);

                itemToEdit.ComBase = model.ComBase;
                itemToEdit.ComCounter = model.ComCounter;
                itemToEdit.Title = model.Title;
                itemToEdit.CodeFXI = model.CodeFXI;
                itemToEdit.MinVolume = model.MinVolume;
                itemToEdit.MinStepVolume = model.MinStepVolume;
                itemToEdit.Precise = model.Precise;
                itemToEdit.SwapBuy = model.SwapBuy;
                itemToEdit.SwapSell = model.SwapSell;
                itemToEdit.Description = model.Description;

                context.SaveChanges();
            }
            catch (Exception ex)
            {
                Logger.Error("EditSpotItem()", ex);
                result = ex.Message;
            }
            finally
            {
                if (newContext != null) newContext.Dispose();
            }
            return result;
        }
        public ActionResult EditSpot(SpotModel model)
        {
            if (!ModelState.IsValid) return Json(new { status = false, errorString = Resource.ErrorMessageInvalid }, JsonRequestBehavior.AllowGet);

            try
            {
                using (var ctx = DatabaseContext.Instance.Make())
                {
                    var result = spotRepository.EditSpotItem(ctx, model);
                    return String.IsNullOrEmpty(result) ?
                        Json(new { status = true }, JsonRequestBehavior.AllowGet) :
                        Json(new { status = false, errorString = Resource.ErrorMessage + ": " + result },
                        JsonRequestBehavior.AllowGet);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("EditSpot() error", ex);
                return Json(new { status = false, errorString = Resource.ErrorMessage + ": " + ex.Message }, JsonRequestBehavior.AllowGet);
            }
        }