Beispiel #1
0
        public async Task <bool> SaveInDatabase(vm.ApartmentForm info)
        {
            if (!ModelState.IsValid(info))
            {
                Notify(ModelState.GetErrors().ToLinesString(), "error");
                return(false);
            }

            var item = info.Item.Clone();

            await info.CopyDataTo(item); // Read the ViewModel data into the domain object.

            using (var scope = Database.CreateTransactionScope())
            {
                try
                {
                    info.Item = await Database.Save(item);

                    scope.Complete();
                    return(true);
                }
                catch (Olive.Entities.ValidationException ex)
                {
                    Notify(ex.ToFullMessage(), "error");
                }

                return(false);
            }
        }
Beispiel #2
0
        public async Task OnBound(vm.ApartmentForm info)
        {
            info.Item = info.Item ?? new Apartment();

            if (Request.IsGet())
            {
                await info.Item.CopyDataTo(info);
            }
        }
Beispiel #3
0
        public async Task <ActionResult> Save(vm.ApartmentForm info)
        {
            try
            {
                if (!await SaveInDatabase(info))
                {
                    return(JsonActions(info));
                }
            }
            catch (Olive.Entities.ValidationException ex)
            {
                return(Notify(ex.Message, "error"));
            }

            Notify("Saved successfully.", obstruct: false);

            return(AjaxRedirect(Url.ReturnUrl()));
        }
Beispiel #4
0
        public async Task <ActionResult> Index(vm.ApartmentForm info)
        {
            ModelState.Clear(); // Remove initial validation messages

            return(View(info));
        }